Solved

Problem With Add New Record

Posted on 2006-07-15
2
211 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 500 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

742 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