Parameter ?_1 has no default value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Irfan

    #1

    Parameter ?_1 has no default value

    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 oledbQueryBuild er 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 OleDbDataAdapte r
    ds = New DataSet()
    Dim cmd As New OleDbCommand("S ELECT id,name from table1", con)
    da.SelectComman d = 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.LongV arWChar)
    Dim par2 As New OleDbParameter( "Name", OleDbType.VarCh ar)
    'add parameters
    cmdInsert.Param eters.Add(par1)
    cmdInsert.Param eters.Add(par2)
    da.InsertComman d = cmdInsert



  • Ken Tucker [MVP]

    #2
    Re: Parameter ?_1 has no default value

    Hi,

    http://msdn.microsoft.com/library/de...andbuilder.asp

    Ken
    --------------------
    "Irfan" <irfan@asc-ltd.co.uk> wrote in message
    news:ucI5$52cFH A.1404@TK2MSFTN GP09.phx.gbl...
    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 oledbQueryBuild er 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 OleDbDataAdapte r
    ds = New DataSet()
    Dim cmd As New OleDbCommand("S ELECT id,name from table1", con)
    da.SelectComman d = 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.LongV arWChar)
    Dim par2 As New OleDbParameter( "Name", OleDbType.VarCh ar)
    'add parameters
    cmdInsert.Param eters.Add(par1)
    cmdInsert.Param eters.Add(par2)
    da.InsertComman d = cmdInsert




    Comment

    Working...