데이터베이스 : 값이인 ConnStr이라는 Microsoft Access 생성 된 설정 공급자 = Microsoft.ACE.OLEDB.12.0; 데이터 원본 = C : \ sm.accdb 제품 테이블은 4 개의 C 럼이 제품 ID, 설명, 카테고리, 가격 나는 3 개 클래스가 : 데이터베이스, 관리자, 제품을 ProductManagerID로 제품을 얻는 방법?
Public MustInherit Class Manager
Private _connectionString As String
Protected Property ConnectionString() As String
Get
Return _connectionString
End Get
Set(ByVal value As String)
_connectionString = value
End Set
End Property
Public Sub New(ByVal connStr As String)
ConnectionString = connStr
End Sub
End Class
Public Class Product
Private _id As Integer
Public Property ID() As Integer
Get
Return _id
End Get
Set(ByVal value As Integer)
_id = value
End Set
End Property
Private _description As String
Public Property Description() As String
Get
Return _description
End Get
Set(ByVal value As String)
_description = value
End Set
End Property
Private _category As String
Public Property Category() As String
Get
Return _category
End Get
Set(ByVal value As String)
_category = value
End Set
End Property
Private _price As Double
Public Property Price() As Double
Get
Return _price
End Get
Set(ByVal value As Double)
_price = value
End Set
End Property
End Class
Imports System.Data.OleDb
Public Class ProductManager
Inherits Manager
Public Function GetProductByID(ByVal id As Integer) As Product
Dim con = New System.Data.OleDb.OleDbConnection
Dim sql As String = "SELECT * FROM Product WHERE [email protected]"
con.Open()
Try
Dim description As String
Dim category As String
Dim price As Double
Dim cmd As New System.Data.OleDb.OleDbCommand(sql, con)
cmd.Parameters.Add(id.ToString, "@id")
cmd.Parameters.Add(description, "@description")
cmd.Parameters.Add(category, "@category")
cmd.Parameters.Add(price.ToString, "@price")
cmd.ExecuteNonQuery()
cmd.Dispose()
cmd = Nothing
Catch ex As Exception
Throw New Exception(ex.ToString(), ex)
Finally
con.Close()
End Try
Return nothing
End Function
End Class
내가 얻을 수있는 제품 ! 문제는 ProductManager 클래스에 있다고 생각합니다! 나 진짜 혼란 스럽다! 제발 도와주세요!
사용해야합니다? 당신은 그것보다 구체적이어야합니다. – JohnFx
당신의 매개 변수와'cmd.ExecuteNonQuery'가 비명입니다! 선택입니까? –
내가 cmd.ExecuteNonQuery를 변경해야합니까? –