Errors on update code. Could someone help?

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

Dim sqlcmd1 As New SqlClient.SqlCommand()
Dim sqlcon1 As New SqlClient.SqlConnection()
Dim ds1 As New DataSet()
Dim da1 As New SqlClient.SqlDataAdapter()
Dim dt1 As New DataTable()
sqlcon1.ConnectionString = "Server=CHANGED;User
ID=CHANGED;password=CHANGED;Database=Pursuit"
sqlcon1.Open()
sqlcmd1.CommandText = "Update person set Name_Full = " &
TextBox4.Text & ", Name_First =" & TextBox2.Text & ", Name_Last = " &
TextBox3.Text & ", Company1 = " & TextBox5.Text & ", RecordType = " &
TextBox6.Text & ", ClientType = " & TextBox7.Text & ", Phone = " &
TextBox8.Text & ", BPhone= " & TextBox9.Text & ", BPhone_Extension = " &
TextBox10.Text & ", CellPhone = " & TextBox11.Text & " where person_id = "
& Session("PID") & ""
sqlcmd1.Connection = sqlcon1
da1.UpdateCommand = sqlcmd1
da1.Update(ds1, "Person")
sqlcon1.Close()

When I execute this code I get an error stating:
Update unable to find TableMapping['Person'] or DataTable 'Person'.

I am not sure how to correct this.

Could anyone lend a hand?

The
 
Aaron said:
Dim sqlcmd1 As New SqlClient.SqlCommand()
Dim sqlcon1 As New SqlClient.SqlConnection()
Dim ds1 As New DataSet()
Dim da1 As New SqlClient.SqlDataAdapter()
Dim dt1 As New DataTable()
sqlcon1.ConnectionString = "Server=CHANGED;User
ID=CHANGED;password=CHANGED;Database=Pursuit"
sqlcon1.Open()
sqlcmd1.CommandText = "Update person set Name_Full = " &
TextBox4.Text & ", Name_First =" & TextBox2.Text & ", Name_Last = " &
TextBox3.Text & ", Company1 = " & TextBox5.Text & ", RecordType = " &
TextBox6.Text & ", ClientType = " & TextBox7.Text & ", Phone = " &
TextBox8.Text & ", BPhone= " & TextBox9.Text & ", BPhone_Extension = " &
TextBox10.Text & ", CellPhone = " & TextBox11.Text & " where person_id = "
& Session("PID") & ""
sqlcmd1.Connection = sqlcon1
da1.UpdateCommand = sqlcmd1
da1.Update(ds1, "Person")
sqlcon1.Close()

When I execute this code I get an error stating:
Update unable to find TableMapping['Person'] or DataTable 'Person'.

I am not sure how to correct this.

Could anyone lend a hand?

The idea of calling DataAdapter.Update is to update the database with
data which is in the dataset. In this case, you don't *have* any data
in the dataset. If you've got all the information yourself, you can
just call SqlCommand.ExecuteNonQuery, and bypass the dataset and data
adapter entirely.

However, I would *strongly* urge you to use parameters instead of a
single big SQL statement - the above is a serious security hole.
 
Aaron:

What does your DataAdapter.Fill statement look like? I'm guessing you don't
have a atable named Person ni that dataset. You can always use the numeric
index to avoid spelling errors, but it looks like it doesn't have a Table
named Person. Check the spelling, and make sure that the Fill statement
looks like
da1.Fill(ds1, "Person")
If the variable name is person it's not going to work.

Also, do yourself a favor and get rid of that concatentated dynamic SQL.
Either convert it to a stored procedure or use Parameters. There are tons
of reasons not to use dynamic sql, Performance, reliability and security
being the 3 big ones but trust me, there's no upside to not using params and
a Lot of downside. This isn't the problem you are having, but it's a
problem nonetheless.

HTH,

Bill
 
Back
Top