944,048 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 20116
  • ASP.NET RSS
Aug 2nd, 2006
0

How to Update a Data Table?

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbgaya is offline Offline
14 posts
since Aug 2006
Aug 6th, 2006
0

Re: How to Update a Data Table?

There's no need to use DataSet for a simple operation like this.

This should do it:
ASP.NET Syntax (Toggle Plain Text)
  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()
Reputation Points: 10
Solved Threads: 5
Junior Poster
madmital is offline Offline
119 posts
since Jun 2005
Oct 6th, 2007
0

Re: How to Update a Data Table?

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Phillip is offline Offline
1 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Format GridView Columns
Next Thread in ASP.NET Forum Timeline: How to get the current web page information in asp.net?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC