3
Contributors
10
Replies
14
Views
8 Years
Discussion Span
Last Post by ggl0rd
0

Try using the SqlCommandBuilder Class like this

SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);

 mySqlDataAdapter.Update(myDataSet, "myTableName");
0

Tried that but its not working. Do i have to set the update,delete and insert command?

Try using the SqlCommandBuilder Class like this

SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);

 mySqlDataAdapter.Update(myDataSet, "myTableName");
0

Here is the code

SqlDataAdapter da = new SqlDataAdapter("select * from mytable",strCon);
        DataSet ds = new DataSet();
        da.Fill(ds);

        GridView2.DataSource = ds;
        GridView2.DataBind();
        SqlCommandBuilder m_cd = new SqlCommandBuilder(da);
        string UpdateCommand = m_cd.GetUpdateCommand().CommandText;
             
        da.Update(ds, "mytable");
0

Try this:

SqlDataAdapter da = new SqlDataAdapter("select * from mytable",strCon);
SqlCommandBuilder m_cd = new SqlCommandBuilder(da);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;

        DataSet ds = new DataSet();
        da.Fill(ds);

        GridView2.DataSource = ds;
        GridView2.DataBind();
        
        string UpdateCommand = m_cd.GetUpdateCommand().CommandText;
             
        da.Update(ds, "mytable");
0

Throwing an error as

Update unable to find TableMapping['mytable'] or DataTable 'mytable'

Try this:

SqlDataAdapter da = new SqlDataAdapter("select * from mytable",strCon);
SqlCommandBuilder m_cd = new SqlCommandBuilder(da);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;

        DataSet ds = new DataSet();
        da.Fill(ds);

        GridView2.DataSource = ds;
        GridView2.DataBind();
        
        string UpdateCommand = m_cd.GetUpdateCommand().CommandText;
             
        da.Update(ds, "mytable");
0

da.Update(ds, "mytable");

Here "mytable" should be replace by your tablename. I have given it just as an example. Since your Dataset contains only one table you can use this instead.

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

0

i had replaced it with my table name.Still it was showing that error. while changing it to

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

as you suggested, no updation was done on the table

0

finally i hv found the solution. i was actually tryng to update MS access. for that you have to check the permissions of the table and give proper permissions

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.