How to Update a Data Table?

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 14
Reputation: vbgaya is an unknown quantity at this point 
Solved Threads: 0
vbgaya vbgaya is offline Offline
Newbie Poster

How to Update a Data Table?

 
0
  #1
Aug 2nd, 2006
I have written some coding to add a new row to
an existing data table. After clicking the submit
button I get following error.
"Update requires a valid InsertCommand when
passed DataRow collection with new rows."
Please tell me what the additional code I should
add. The "add" method is called after a user
clicking the submit button. I didn't include the
HTML stuff here.
Here is the code,
<script runat="server">
sub add(obj as object, e as EventArgs)
dim objConn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\scms\database\scms.mdb")
dim objCmd as new OleDbDataAdapter("select * from services", objConn)
dim ds as DataSet = new DataSet()
objCmd.Fill(ds, "services")
dim dr as DataRow = ds.Tables("services").NewRow()
dr(1)=txtServiceName.text
dr(2)=txtSinhalaShortTag.Text
dr(3)=txtTamilShortTag.Text
dr(4)=txtEnglishShortTag.Text
ds.Tables("services").Rows.Add(dr)
objCmd.Update(ds, "services")
end sub
</script>
Please help me. I can't figure out what to do.
vbgaya.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 107
Reputation: madmital is an unknown quantity at this point 
Solved Threads: 3
madmital madmital is offline Offline
Junior Poster

Re: How to Update a Data Table?

 
0
  #2
Aug 6th, 2006
There's no need to use DataSet for a simple operation like this.

This should do it:
  1. Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\scms\database\scms.mdb") : conn.Open()
  2. Dim insCom As New OleDbCommand("INSERT INTO services (col1, col2, col3, col3) VALUES('" & txtServiceName.text & "', '" & txtSinhalaShortTag.Text & "', '" & txtTamilShortTag.Text & "', '" & txtEnglishShortTag.Text & "'", conn)
  3. insCom.ExecuteNonQuery()
Web Developer
When something seems too good to be true...it usually is
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1
Reputation: Phillip is an unknown quantity at this point 
Solved Threads: 0
Phillip Phillip is offline Offline
Newbie Poster

Re: How to Update a Data Table?

 
0
  #3
Oct 6th, 2007
OK - But that does NOT answer the question
Why is the Update command giving an error
Last edited by Phillip; Oct 6th, 2007 at 6:31 pm.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC