Hi Triffid,
you can refer to the code below to update your database using the coommand
builder by generating the update command automatically.
protected void Button1_Click(object sender, EventArgs e)
{
string connstr = "provider = SQLOLEDB; data source =
in-ts-manish\\sqlexpress; integrated security = SSPI; database = pubs";
OleDbConnection myconn = new OleDbConnection(connstr);
// Create a dataset.
DataSet ds = new DataSet();
// Create dataadapters for each tables.
OleDbDataAdapter myadpt = new OleDbDataAdapter("select *
from dbo.authors", myconn);
myadpt.Fill(ds,"authors");
ds.Tables["authors"].Rows[1]["au_lname"] = "Singhal";
OleDbCommandBuilder scb = new OleDbCommandBuilder(myadpt);
myadpt.UpdateCommand = scb.GetUpdateCommand();
myadpt.Update(ds,"authors");
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
Regards,
Manish
www.componentone.com
> Hi there,
>
[quoted text clipped - 23 lines]
>
> - Triffid
triffid@oink.co.uk - 18 Dec 2007 21:27 GMT
> HiTriffid,
>
> you can refer to the code below to update your database using the coommand
> builder by generating the update command automatically.
Thanks for the feedback; I adapted your code for my situation (using
my Access/Jet DB instead of SQL Server).
Although it overcame the problem I was having, unfortunately it then
ran into the exact same problem I had the last time I tried
OleDbCommandBuilder (now I remember...).
Specifically, it complained about syntax errors in the generated SQL.
Doing a Google on this problem, it seemed that it had something to do
with field names containing spaces. So I renamed all the fields in the
database, updated the code, and.... it seems to work.
Either OleDbCommandBuilder isn't particularly smart and requires
convoluted workarounds, or I've missed something, but I'm going to
look into this sometime.
Anyway, thanks for your help- at least I'm halfway there next time :)
- Triffid