Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 ADO.NET How to update dataset ?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

GoodMorningSky
Junior Member

122 Posts

Posted - 06 May 2004 :  14:37:11  Show Profile
hi, all.
I have a form with a data grid that is bound to Dataset, which has two table and relationship between those.
After a user modify data using datagrid, I want to update the data but, it gives error saying I need update command..
I tried in several way to do it, it failed...
Please reply with code that I need for this..
Thank you all...

Here are my situation in code..


public class frmLocalServerInfo : System.Windows.Forms.Form
{
private SqlConnection cnn;
private SqlDataAdapter adp1;
private SqlDataAdapter adp2;
private DataTable tblDBLogInfo, tblDept_DBLogInfo;
private DataSet ds;
private System.Windows.Forms.DataGrid dgServerInfo;
private System.Windows.Forms.Button btSave;
private System.Windows.Forms.Button btCancel;
private void frmLocalServerInfo_Load(object sender, System.EventArgs e)
{
string cnnstr=ConfigurationSettings.AppSettings["HQConnectionString"].ToString();
cnn = new SqlConnection();
cnn.ConnectionString = cnnstr;
adp1 = new SqlDataAdapter("SELECT ID, CompanyCode, DepartmentCode , DBIpAddr FROM tblDBLogInfo", cnn);
adp2 = new SqlDataAdapter("SELECT CompanyCode, DepartmentCode, DBLogInfoID FROM tblDept_DBLogInfo", cnn);

//Some code goes here for update command...
tblDBLogInfo = new DataTable();
tblDBLogInfo.TableName = "tblDBLogInfo";
tblDept_DBLogInfo = new DataTable();
tblDept_DBLogInfo.TableName = "tblDept_DBLogInfo";
adp1.Fill(this.tblDBLogInfo);
adp2.Fill(this.tblDept_DBLogInfo);
ds = new DataSet();
ds.Tables.Add(this.tblDBLogInfo);
ds.Tables.Add(this.tblDept_DBLogInfo);
ds.Relations.Add("Sharing Departments", this.tblDBLogInfo.Columns["ID"], this.tblDept_DBLogInfo.Columns["DBLogInfoID"]);
this.dgServerInfo.DataSource = ds;
this.dgServerInfo.DataMember = "tblDBLogInfo";
}

private void btSave_Click(object sender, System.EventArgs e)
{
// some code goes here.... I guess..

this.adp1.Update(this.tblDBLogInfo);
this.adp2.Update(this.tblDept_DBLogInfo);
this.Close();
}
[/CODE]

Software Engineer.
MCSD.NET, SCWCD

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 06 May 2004 :  15:35:56  Show Profile
you need to set the UpdateCommand on the SqlDataAdapter, I haven't done it using 2 DataTables with relations but you'll probably need the UpdateCommand on both SqlDataAdaptor's

If you are using VS.NET, create a new form and follow the wizard and let the designer create the code, then you can see what you need to do, that's how I learnt.

The UK MkIVs Forum
Go to Top of Page

GoodMorningSky
Junior Member

122 Posts

Posted - 06 May 2004 :  17:55:38  Show Profile
thank you for reply.
I know I need update command.
but, I want to know how to make UpdateCommand object for this case...

Software Engineer.
MCSD.NET, SCWCD
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.34 seconds. Powered By: Snitz Forums 2000 Version 3.4.07