Adding Record Problem

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.
LVL 1
yirehAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Bob LearnedConnect With a Mentor Commented:
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
 
jtaylor8181Commented:
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
 
jtaylor8181Commented:
This is assuming that the there is nothing wrong with the dataadapter.  But make sure you replace ds for dt.

jtaylor8181
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.