Solved

Problem With Add New Record

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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