ADO.NET Beginner

R

Richard Rivera

I have a method called InsertUpdate which I want to use to handle both
insert's and update's. The GUI has a 2 textboxes: First Name and Last Name.
This is what my InsertUpdate method looks like right now.

InsertUpdate method:

SqlConnection cn = new SqlConnection("Initial Catalog=TEST;Data
Source=Server1;Integrated Security= SSPI");
SqlDataAdapter da = new SqlDataAdapter("SELECT ID, FIRST_NAME, LAST_NAME
FROM TableName",cn);

SqlCommandBuilder thisBuilder = new SqlCommandBuilder(da);

DataSet ds = new DataSet();

da.Fill(ds,"TableName");


DataRow thisRow = ds.Tables["TableName"].NewRow();

thisRow["FIRST_NAME"] = txtFirstName.Text;

thisRow["LAST_NAME"] = txtLastName.Text;

ds.Tables["PLAYERS"].Rows.Add(thisRow);

da.Update(ds, "PLAYERS");

The next time I call the InsertUpdate method I want to update my data. How
do I do this with the code above? It obviously works for an insert but how
do I check if the data is dirty? so I can update my data. Any help would be
appreciated.

Richard

(e-mail address removed)
 
M

Miha Markic

How
do I do this with the code above? It obviously works for an insert but how
do I check if the data is dirty? so I can update my data. Any help would be
appreciated.

DataSet.HasChanges
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top