Update when using sql server doesn't work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TonyJ

    Update when using sql server doesn't work

    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(obje ct sender, EventArgs e)
    {
    // TODO: This line of code loads data into the
    'minDatabasData Set1.Kunder' table. You can move, or remove it, as needed.
    this.kunderTabl eAdapter.Fill(t his.minDatabasD ataSet1.Kunder) ;
    this.kunderTabl eAdapter.
    }

    private void buttonUpdate_Cl ick(object sender, EventArgs e)
    {
    this.kunderTabl eAdapter.Update (this.minDataba sDataSet1.Kunde r);
    }



    //Tony


  • Morten Wennevik [C# MVP]

    #2
    Re: Update when using sql server doesn't work

    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 test1ToolStripM enuItem_Click(o bject sender, EventArgs e)
    {
    using (SqlConnection conn = new SqlConnection(" Data Source=(local); Initial Catalog=Adventu reWorks;Integra ted Security=SSPI;" ))
    {
    using (SqlCommand com = new SqlCommand("SEL ECT * FROMProduction. Culture", conn))
    {
    using (da = new SqlDataAdapter( com))
    {
    da.Fill(ds);
    dataGridView1.D ataSource = ds;
    dataGridView1.D ataMember = "Table";
    }
    }
    }
    }

    private void test2ToolStripM enuItem_Click(o bject sender, EventArgs e)
    {
    using (SqlConnection conn = new SqlConnection(" Data Source=(local); Initial Catalog=Adventu reWorks;Integra ted Security=SSPI;" ))
    {
    using (SqlCommand com = new SqlCommand("SEL ECT * FROMProduction. Culture", conn))
    {
    using (da = new SqlDataAdapter( com))
    {
    using (SqlCommandBuil der b = new SqlCommandBuild er(da))
    {
    da.Update(ds);
    }
    }
    }
    }
    }


    On Fri, 29 Jun 2007 08:43:36 +0200, TonyJ <johansson.ande rsson@telia.com wrote:
    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(obje ct sender, EventArgs e)
    {
    // TODO: This line of code loads data into the
    'minDatabasData Set1.Kunder' table. You can move, or remove it, as needed.
    this.kunderTabl eAdapter.Fill(t his.minDatabasD ataSet1.Kunder) ;
    this.kunderTabl eAdapter.
    }
    >
    private void buttonUpdate_Cl ick(object sender, EventArgs e)
    {
    this.kunderTabl eAdapter.Update (this.minDataba sDataSet1.Kunde r);
    }
    >
    >
    >
    //Tony
    >
    >
    >


    --
    Happy coding!
    Morten Wennevik [C# MVP]

    Comment

    Working...