Update when using sql server doesn't work

T

TonyJ

Hello!

I trying to update a table using sql server but no update will be done.

I don't get any error at all.



Here is an extract from the code. Does this seems to be right.

I have a Dataset and an Adapter

private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'minDatabasDataSet1.Kunder' table. You can move, or remove it, as needed.
this.kunderTableAdapter.Fill(this.minDatabasDataSet1.Kunder);
this.kunderTableAdapter.
}

private void buttonUpdate_Click(object sender, EventArgs e)
{
this.kunderTableAdapter.Update(this.minDatabasDataSet1.Kunder);
}



//Tony
 
M

Morten Wennevik [C# MVP]

Hi Tony,

There is nothing here that explains why your updates don't work. Need more code for that. What is the UpdateCommand string at the time of the update?

You could also try to adapt the code below, which should update the table (although that particular AdventureWorks table has some triggers updating the date field behind the scenes that may cause concurrency problemson the second update)

SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
private void test1ToolStripMenuItem_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=SSPI;"))
{
using (SqlCommand com = new SqlCommand("SELECT * FROMProduction.Culture", conn))
{
using (da = new SqlDataAdapter(com))
{
da.Fill(ds);
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Table";
}
}
}
}

private void test2ToolStripMenuItem_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=SSPI;"))
{
using (SqlCommand com = new SqlCommand("SELECT * FROMProduction.Culture", conn))
{
using (da = new SqlDataAdapter(com))
{
using (SqlCommandBuilder b = new SqlCommandBuilder(da))
{
da.Update(ds);
}
}
}
}
}
 

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