Xin chào Tôi đã gặp một vấn đề trong khi tạo dự án trường học của tôi.Lấy các giá trị lớp dựa trên khóa
Một số mô tả:
Liệt kê - đối tượng của nó và được nối thêm bằng truy vấn sql và sau đó trở thành danh sách liệt kê. Khách hàng - Khách hàng: id, tên, họ
Listy sql đổ dụ
id+ number +letters+forwho+bywho+created +prority+type
7 900000170300000935295877 0 3 202 2013-11-27 16:37:55 0 1
Vấn đề
xem DataGrid của tôi trông giống hệt theo cùng một cách như là kết quả mysql, những gì tôi muốn nhận được là một màn hình hiển thị thân thiện hơn vì vậy nếu tôi có byhwo 202 (một id khách hàng của nó) tôi muốn được hiển thị trong xem datagrid Ví dụ Tên Họ Tên. Nó phải được thực hiện với mã này bằng cách nào đó. Ngoài ra một tính năng tốt đẹp sẽ có khả năng xóa và cập nhật một Class Client bằng cách nào đó.
Lớp Lõi
Class Core
Dim gridDataList As New BindingList(Of Listy)
Dim cmd As New MySqlCommand
Dim da As New MySqlDataAdapter
Dim con As MySqlConnection = jokenconn()
Public list As New List(Of Customers)
Public Function jokenconn() As MySqlConnection
Return New MySqlConnection(.......)
End Function
Public Sub init_customers()
' Create a list of strings.
Dim sql As String
Dim myReader As MySqlDataReader
con.Open()
sql = "select * from customers"
'bind the connection and query
With cmd
.Connection = con
.CommandText = sql
End With
myReader = cmd.ExecuteReader()
While myReader.Read()
list.Add(New Customers(myReader.GetInt64(0), myReader.GetString(1), myReader.GetString(2)))
End While
con.Close()
End Sub
Public Function display_single_name()
Return 0
'Dim pinfo As propertyinfo = GetType(String).GetProperty("")
'here i want to return the name and surname of client based on a number/id
End Function
End Class
Lớp Khách hàng
Class Customers
Public Sub New(ByVal id As Integer, ByVal name As String, ByVal surname As String)
Me.ID = id
Me.Imie = name
Me.Nazwisko = surname
End Sub
#Region "Get/Set"
Public Property ID() As Integer
Get
Return Me._id
End Get
Set(ByVal value As Integer)
Me._id = value
End Set
End Property
Public Property Imie() As String
Get
Return Me._imie
End Get
Set(ByVal value As String)
Me._imie = value
End Set
End Property
Public Property Nazwisko() As String
Get
Return Me._nazwisko
End Get
Set(ByVal value As String)
Me._nazwisko = value
End Set
End Property
#End Region
Private _id As Integer
Private _imie As String
Private _nazwisko As String
End Class
Lớp Listy
Class Listy
' Private _comments As String
' Private _firstName As String
' Private _secondName As String
Public Sub New(ByVal id As Integer, ByVal listnumb As String, ByVal list_count As Integer, ByVal by_who As Integer, ByVal for_who As Integer, ByVal created As Date, ByVal prority As Integer, ByVal type As Integer)
Me.ID = id
Me.Lista = listnumb
Me.Listów = list_count
Me.Wystawione_przez = by_who
Me.Wystawione_na = for_who
Me.Priorytet = prority
Me.Rodzaj_Listy = type
Me.Utworzono = created
End Sub
#Region "Get/Set"
Public Property ID() As Integer
Get
Return Me._id
End Get
Set(ByVal value As Integer)
Me._id = value
End Set
End Property
Public Property Lista() As String
Get
Return Me._list_Number
End Get
Set(ByVal value As String)
Me._list_Number = value
End Set
End Property
Public Property Listów() As Integer
Get
Return Me._Lst_Count
End Get
Set(ByVal value As Integer)
Me._Lst_Count = value
End Set
End Property
Public Property Wystawione_przez() As Integer
Get
Return Me._bywho
End Get
Set(ByVal value As Integer)
Me._bywho = value
End Set
End Property
Public Property Wystawione_na() As Integer
Get
Return Me._forwho
End Get
Set(ByVal value As Integer)
Me._forwho = value
End Set
End Property
Public Property Priorytet() As Integer
Get
Return Me._prority
End Get
Set(ByVal value As Integer)
Me._prority = value
End Set
End Property
Public Property Rodzaj_Listy() As Integer
Get
Return Me._type
End Get
Set(ByVal value As Integer)
Me._type = value
End Set
End Property
Public Property Utworzono() As Date
Get
Return Me._date
End Get
Set(ByVal value As Date)
Me._date = value
End Set
End Property
#End Region
Private _id As Integer
Private _Lst_Count As Integer
Private _bywho As Integer
Private _forwho As Integer
Private _prority As Integer
Private _type As Integer
Private _date As Date
Private _list_Number As String
End Class
Câu hỏi của bạn hiện đang kết hợp trong rất nhiều từ buzz kỹ thuật và hầu như không cung cấp thông tin hữu ích về sự cố. Đừng cố giải thích mã, hoặc cách tiếp cận bạn đã thử. Cố gắng giải thích vấn đề thực tế bạn đang cố gắng giải quyết, bằng tiếng Anh. Cố gắng càng cụ thể càng tốt, sử dụng 20 từ hoặc hơn. Sau đó bạn có thể xây dựng thêm về nó. – Neolisk
@Neolisk Ok hãy để tôi rút ngắn điều này: Lớp Khách hàng (get/set property), tôi có một hàm để nối kết quả sql vào lớp khách hàng (list.add new customer) những gì tôi muốn là khả năng lấy ví dụ cho khách hàng (1) 1 là id và trả về ví dụ là tên và họ của khách hàng – Kavvson
Vì vậy, bạn muốn "chọn * từ khách hàng WHERE customer_id = 1", sau đó danh sách khách hàng của bạn chứa chính xác một mục? – Neolisk