[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Adding Record Problem

Posted on 2006-07-03
3
Medium Priority
?
248 Views
Last Modified: 2010-04-23
Hi:

I'm new to vb.net. I'm programmer of VB6

I'm trying to add new record to sql table called "Users" and have an error message.

The Code used is;

        Dim strQuery As String = "Select * From Users"
        Dim ds As New DataSet("Users")
        Dim da As New SqlClient.SqlDataAdapter(strQuery, dbConn)
        da.Fill(ds)

        Dim dr As DataRow = ds.Tables(0).NewRow
        dr.Item("USER_ID") = "data"
        dr.Item("PASSWORD") = "data2"
        dr.EndEdit()
        ds.Tables(0).Rows.Add(dr)
        da.Update(ds, "Users") '****>>> Update unable to find TableMapping['Users'] or DataTable 'Users'.

Thanks in advance for your help.
0
Comment
Question by:yireh
  • 2
3 Comments
 
LVL 4

Expert Comment

by:jtaylor8181
ID: 17033587
Instead of DataSet("Users")
try
Dim dt as New DataTable("User")

Also, sometimes you have to use a different name from the actual database table for the datatable or dataset.

jtaylor8181
0
 
LVL 4

Expert Comment

by:jtaylor8181
ID: 17033596
This is assuming that the there is nothing wrong with the dataadapter.  But make sure you replace ds for dt.

jtaylor8181
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 750 total points
ID: 17033738
It looks like you didn't specify an UpdateCommand and an InsertCommand for the data adapter.  You can use an SqlCommandBuilder to do that from the SelectCommand.

Bob
0

Featured Post

Independent Software Vendors: 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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month18 days, 19 hours left to enroll

834 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