How update DB table with DataSet

Posted by Paul on Stack Overflow See other posts from Stack Overflow or by Paul
Published on 2010-03-26T15:18:38Z Indexed on 2010/03/29 2:33 UTC
Read the original article Hit count: 386

Filed under:

I am begginer with ADO.NET , I try update table with DataSet. O client side I have dataset with one table. I send this dataset on service side (it is ASP.NET Web Service). On Service side I try update table in database, but it dont 't work.

public bool Update(DataSet ds) {

    SqlConnection conn = null;
    SqlDataAdapter da = null;
    SqlCommand cmd = null;
    try
    {

        string sql = "UPDATE * FROM Tab1";

        string connStr = WebConfigurationManager.ConnectionStrings["Employees"].ConnectionString;

        conn = new SqlConnection(connStr);
        conn.Open();

        cmd=new SqlCommand(sql,conn);

        da = new SqlDataAdapter(sql, conn);
        da.UpdateCommand = cmd;

        da.Update(ds.Tables[0]);
        return true;

    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {
        if (conn != null)
            conn.Close();
        if (da != null)
            da.Dispose();
    }
}

Where can be problem?

© Stack Overflow or respective owner

Related posts about ADO.NET