about the AddWithValue method of oledbcommand  
Author Message
cowboy in VB





PostPosted: .NET Framework Data Access and Storage, about the AddWithValue method of oledbcommand Top

I found that the 'Addwithvalue' do not add the value to the parameter by the name specified, but by the sequence of the 'Addwith value'. the following codes (the second parameter get value earlier than the first parameter) always produce error 'the field is less than the datat provided'

' Add parameters for the placeholders in the SQL in the
' CommandText property...

objCommand.CommandText = ""

objCommand.Parameters.Clear() 'clear previous param

' Parameter for the title_id column...

' Parameter for the au_id column...


' Execute the SqlCommand object to insert the new data...
objCommand.ExecuteNonQuery()

Catch OleDbExceptionErr As OleDbException
MessageBox.Show(OleDbExceptionErr.Message)
ToolStripStatusLabel1.Text = "Add Fail"
End Try

if i change the sequence of the Addwithvalue as follows, no error appear. who can tell me why this happened Thanks

' Parameter for the au_id column...

' Parameter for the title_id column...




.NET Development3