Parameter ?_1 has no default value

I

Irfan

hi,

This is not something very complicated that i am trying to do. All i am
doing is put data in a datagrid and using a
customised Insert query to insert a row. The data does appear on the
datagrid, but when i insert a new row and use da.update(ds,dt) it gives
this error.

The same thing works fine if i use oledbQueryBuilder instead of my own
InsertCommand, but querybuilder does not usually fulfill the purpose always.
I created a very simplified AccessDatabase with just a table having two
columns.


Please see the code below and i would appreciate ur suggestions.
TIA
irfan

Dim con As New OleDbConnection(ConnString)
da = New OleDbDataAdapter
ds = New DataSet()
Dim cmd As New OleDbCommand("SELECT id,name from table1", con)
da.SelectCommand = cmd
da.Fill(ds, "mytable")

'create an insert command
Dim cmdInsert As New OleDbCommand( _
"INSERT INTO Table1( id, Name) VALUES (?,?)", con)
'create parameter
Dim par1 As New OleDbParameter("id", OleDbType.LongVarWChar)
Dim par2 As New OleDbParameter("Name", OleDbType.VarChar)
'add parameters
cmdInsert.Parameters.Add(par1)
cmdInsert.Parameters.Add(par2)
da.InsertCommand = cmdInsert
 
K

Ken Tucker [MVP]

Hi,

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/html/commandbuilder.asp

Ken
--------------------
hi,

This is not something very complicated that i am trying to do. All i am
doing is put data in a datagrid and using a
customised Insert query to insert a row. The data does appear on the
datagrid, but when i insert a new row and use da.update(ds,dt) it gives
this error.

The same thing works fine if i use oledbQueryBuilder instead of my own
InsertCommand, but querybuilder does not usually fulfill the purpose always.
I created a very simplified AccessDatabase with just a table having two
columns.


Please see the code below and i would appreciate ur suggestions.
TIA
irfan

Dim con As New OleDbConnection(ConnString)
da = New OleDbDataAdapter
ds = New DataSet()
Dim cmd As New OleDbCommand("SELECT id,name from table1", con)
da.SelectCommand = cmd
da.Fill(ds, "mytable")

'create an insert command
Dim cmdInsert As New OleDbCommand( _
"INSERT INTO Table1( id, Name) VALUES (?,?)", con)
'create parameter
Dim par1 As New OleDbParameter("id", OleDbType.LongVarWChar)
Dim par2 As New OleDbParameter("Name", OleDbType.VarChar)
'add parameters
cmdInsert.Parameters.Add(par1)
cmdInsert.Parameters.Add(par2)
da.InsertCommand = cmdInsert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top