Link to home
Start Free TrialLog in
Avatar of yireh
yireh

asked on

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.
Avatar of jtaylor8181
jtaylor8181

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
This is assuming that the there is nothing wrong with the dataadapter.  But make sure you replace ds for dt.

jtaylor8181
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial