Very basic stupid question

M

mo

Hi,
I am trying to insert/update to a sql server and It does not either
insert or updates but the code does not fail (it is doing something)
any ideas?
try
{
string connString = "Data Source=server1;Initial Catalog=Test;User
ID=sa;Password=;";
SqlConnection myConnection = new SqlConnection(connString);
SqlDataAdapter mysqlDataAdapter = new SqlDataAdapter("SELECT *
from Links",myConnection);
myConnection.Open();
DataSet myDataSet = new DataSet();
DataRow mydataRow;
SqlCommandBuilder mySqlCommandBuilder =new
SqlCommandBuilder(mysqlDataAdapter);
mysqlDataAdapter.MissingSchemaAction=MissingSchemaAction.AddWithKey;
mysqlDataAdapter.Fill(myDataSet,"Links");
myDataSet.Tables["Links"].Rows[0]["Name"] = "peach";
mydataRow = myDataSet.Tables["Links"].NewRow();
mydataRow["Name"] = "xxxx";
label2.Text = "inserted in the table";
myDataSet.Tables["Links"].Rows.Add(mydataRow);

myConnection.Close();
}
catch
{
label2.Text = "database insert failed ";
}
 
B

Bernie Yaeger

Hi mo,

You don't have an update call. In VB .Net it works like this:
Try

da.Update(ds, "d")

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

HTH,

Bernie Yaeger
 

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