Fathurrohman Elkusnandi Fathurrohman Elkusnandi - 4 years ago 181
SQL Question

How can I update my SQL table in C#?

I created a program that requires a database and I am using Visual Studio and SQL Server to do it.

My problem is that I cannot update my table. I found the solution here.

My code is below:

this.customersTableAdapter.Update(this.northwindDataSet.Customers);
tabelAdapter.Update(ABCDatabaseDataSet**.Barber)**;


But it gives me an error that the
ABCDatabaseDataSet
does not have
Barber
. There is just
BarberDataTable
or
BarberRow
there is not a
Barber
table.

What am I doing wrong?

Answer Source

Your probably best off doing this with ADO or better LINQ. Heres an ADO example:

    var thisConnection = new SqlConnection("Server=ServerIP/Name;Data Source=Database;Initial Catalog=Database;User ID=User;Password=Pass;Trusted_Connection=False");
    thisConnection.Open();

    var updateSql1 = "UPDATE dbo.Customer " +
                     "SET barber = 'I Barber People !' " +
                     "WHERE customerID = 5";

    var UpdateCmd1 = new SqlCommand(updateSql1, thisConnection);
    UpdateCmd1.ExecuteNonQuery();
    thisConnection.Close();

Too much to place here but here is a good Linq (database) tutorial tutorial

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download