INSERTING RECORD IN THE DATABASE(sURNAME AND TEMPLATE)

Reply

Join Date: May 2008
Posts: 23
Reputation: realone has a little shameless behaviour in the past 
Solved Threads: 0
realone realone is offline Offline
Newbie Poster

INSERTING RECORD IN THE DATABASE(sURNAME AND TEMPLATE)

 
0
  #1
Sep 1st, 2009
' 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")
Last edited by John A; Sep 1st, 2009 at 8:27 pm. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,793
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 698
Sponsor
Featured Poster
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: INSERTING RECORD IN THE DATABASE(sURNAME AND TEMPLATE)

 
0
  #2
Sep 1st, 2009
Why don't you use the IDE and generate a typed dataset? You're making a mess of code there.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3,911
Reputation: adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future adatapost has a brilliant future 
Solved Threads: 704
Moderator
adatapost adatapost is offline Offline
Senior Poster

Re: INSERTING RECORD IN THE DATABASE(sURNAME AND TEMPLATE)

 
0
  #3
Sep 2nd, 2009
  1. da.InsertCommand = New OleDbCommand("INSERT INTO Biodata (surname,template) Values (?,?)",connection)
  2.  
  3. da.InsertCommand.CommandType = CommandType.Text
  4. da.InsertCommand.Parameters.Add("?", OleDbType.VarChar, 50, "surname")
  5. da.InsertCommand.Parameters.Add("?", OleDbType.Binary, template.Size, "template")
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 305 | Replies: 2
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC