Solved

Problem With Add New Record

Posted on 2006-07-15
2
207 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
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
Comment Utility
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
Comment Utility
Thanks a lot Sancler
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now