' Add template and surname  to database. Returns added template ID.
    Public Function AddTemplate(ByRef template As TTemplate) As Long
        Dim da As New OleDbDataAdapter("select * from Biodata", connection)
        Dim txtsurname As System.Windows.Forms.TextBox
        txtsurname = New System.Windows.Forms.TextBox()
        ' Create SQL command containing ? parameter for BLOB.
        da.InsertCommand = New OleDbCommand("INSERT INTO Biodata (surname,template) Values '" + txtsurname.Text + "',(?)", connection)
        da.InsertCommand.CommandType = CommandType.Text
        da.InsertCommand.Parameters.Add("@template", OleDbType.Binary, template.Size, "template")
        da.InsertCommand.Parameters.Add("surname", OleDbType.VarChar, 50, "surname")
        ' Open connection
        connection.Open()

        ' Fill DataSet.
        Dim enroll As DataSet = New DataSet
        da.Fill(enroll, "Biodata")

        ' Add a new row.
        ' Create parameter for ? contained in the SQL statement.
        Dim newRow As DataRow = enroll.Tables("Biodata").NewRow()
        newRow("template") = template.tpt
        newRow("surname") = txtsurname.Text
        enroll.Tables("Biodata").Rows.Add(newRow)

        ' Include an event to fill in the Autonumber value.
        AddHandler da.RowUpdated, New OleDbRowUpdatedEventHandler(AddressOf OnRowUpdated)

        ' Update DataSet.
        da.Update(enroll, "biodata")
        'da.Update(enroll)
        connection.Close()
        ' return ID
        Return newRow("ID")
    End Function

I am having this error Command parameter[1] '' is invalid. in da.Update(enroll, "biodata")

da.InsertCommand = New OleDbCommand("INSERT INTO Biodata (surname,template) Values (?,?)",connection)

da.InsertCommand.CommandType = CommandType.Text
da.InsertCommand.Parameters.Add("?", OleDbType.VarChar, 50, "surname")
da.InsertCommand.Parameters.Add("?", OleDbType.Binary, template.Size, "template")
This article has been dead for over six months. Start a new discussion instead.