thanks a lot for your help. This is the code that i have tried, but it doesn't work....when i tried to use commandtype.Tabledirect, the error message say "Object reference not set to an instance of an object." Public Function GetItemCount(ByVal cartID As String)
As Integer ' Create Instance of Connection and Command Object Dim myConnection2 As OleDbConnection Dim myCommand As OleDbCommand Dim qry As String Dim NumRec As Integer myConnection2 = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= E:\webpage\Database\test.mdb")
qry = "SELECT COUNT(*) FROM shoppingCart WHERE CartID = @CartID" myCommand = New OleDbCommand(qry, myConnection2) 'i have tried this code as well 'myCommand.CommandType = CommandType.TableDirect 'myCommand.CommandText = "SELECT COUNT(*) As NumRec FROM shoppingCart
WHERE CartID = @CartID" 'Dim parameterCartID As OleDbParameter = New OleDbParameter("@CartID", OleDbType.VarChar, 10) 'parameterCartID.Value = cartID 'myCommand.Parameters.Add(parameterCartID) ' Open the connection and execute the Command myConnection2.Open()
myCommand.ExecuteScalar() myConnection2.Close() Return CInt(NumRec) End Function //end of code what's wrong with the code???? thanks christene
christene
Member
75 Points
15 Posts
Re: count the element in a database table
Aug 04, 2003 02:44 AM|LINK