well,i have tried the code....and this is the code that i run, 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(*) As NumRec FROM shoppingCart WHERE CartID = @CartID" myCommand = New OleDbCommand myCommand.Connection
= myConnection2 myCommand.CommandType = CommandType.TableDirect myCommand.CommandText = qry 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 However, it says "too few parameter.Expected 1." for the myCommand.ExecuteScalar(). what is that
mean?how shold i solve this? thanks. christene
christene
Member
75 Points
15 Posts
Re: count the element in a database table
Aug 04, 2003 07:52 AM|LINK