?
Solved

Problem With Add New Record

Posted on 2006-07-15
2
Medium Priority
?
213 Views
Last Modified: 2010-04-23
I have the following code and have an error in updating process.

        Dim strQuery As String = "Select * From Users"
        Dim cmd As New SqlClient.SqlCommand(strQuery, dbConn)
        Dim da As New SqlClient.SqlDataAdapter(cmd)
        da.AcceptChangesDuringFill = True
        Dim ds As New DataSet
        da.Fill(ds, "Users")
        Dim dr As DataRow

        dr = ds.Tables("Users").NewRow

        dr("USER_ID") = txtUserID.Text
        dr("PASSWORD") = txtPassword.Text
        dr("F_NAME") = txtFName.Text
        dr("L_NAME") = txtLName.Text
        dr("ADD_1") = txtAdd1.Text
        dr("ADD_2") = txtAdd2.Text
        dr("ZIP") = txtZip.Text
        dr("SS") = txtSSN.Text
        dr("POSITION") = txtPosition.Text
        dr("PHONE") = txtPhone.Text
        dr("DISCOUNT") = cboDiscount.Text
        dr("B_DATE") = txtBDate.Text
        dr("ACTIVE") = chkActiveUser.Checked
        dr("CHANGE_PASSWORD") = chkChangePassword.Checked
        dr("LOCKED") = chkLocked.Checked
        dr("MODIFY_USERS") = chkModifyUsers.Checked

        ds.Tables("Users").Rows.Add(dr)

        da.Update(ds, "Users")  <--Update requires a valid InsertCommand when passed DataRow collection with new rows.


I need to find any other solution without using Insert SQL statement.




0
Comment
Question by:yireh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 17114581
Add

        Dim cb As New SqlClient.SQLCommandBuilder(da)

immediately after

        Dim da As New SqlClient.SqlDataAdapter(cmd)

Roger
0
 
LVL 1

Author Comment

by:yireh
ID: 17116172
Thanks a lot Sancler
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question