Solved

Adding Record Problem

Posted on 2006-07-03
3
226 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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replacing HTML tags in Textarea/Textbox 5 48
Tabcontrol Caption? 1 31
Help with highlighting rows based on identical values in multiple columns 1 35
Getfiles in vb.net 28 43
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

16 Experts available now in Live!

Get 1:1 Help Now