Solved

Adding Record Problem

Posted on 2006-07-03
3
222 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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