Solved

Problem With Add New Record

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Assigning handler to UserControls in flowlayoutpanel 4 27
Error message when using PrintSocket.Send 7 18
Passing data between Forms 3 20
Code enhancement 4 22
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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