|
 |
aspx_beginners thread: updating or inserting data in dataset's table ?
Message #1 by "Rohit Arora" <rohit_arora@i...> on Sat, 1 Feb 2003 15:32:11 +0530
|
|
Hi group,
I have a dataset and if I have to insert a row in a dataset
tables. How to achieve it ?
For eg.
I have two table Alert and Business Entity name in dataset with structures.
Alert--
AlertID(pk), AlertFromBusinessEntityID
Rel_AlertfromBusinessEntityID_to_AlertTobusinessEntityID ----
AlertFromBusinessEntityID(pk) and a foreign key in Alert table.
AlertToBusinessEntityID
Now how can I just update this in a single go by passing values like
AlertID- 5 AlertFromBusinessEntityID -- 12 AlertToBusinessEntityID -- 15
Alert and Rel_AlertfromBusinessEntityID_to_AlertTobusinessEntityID table
have one to many relation but right now as a simple exercise i hv made one
to one mapping
Now how I am going to insert record in Alert table like --
AlertID- 5 AlertFromBusinessEntityID -- 12 and at the same time insert a
record in Rel_AlertfromBusinessEntityID_to_AlertTobusinessEntityID table
like AlertFromBusinessEntityID -- 12 AlertToBusinessEntityID -- 15
I am using a XmlDataDocument synchronized with dataset. So, I ll be using
xmlDataDocument to update dataset. But I ll appreciate any solution using
either relational way or a heiarchial way. Just needed to get started n will
try to port this in heiarchial manner.
peace
rohit
Message #2 by =?iso-8859-1?q?abhishek=20kumar?= <abhi_augin@y...> on Sat, 1 Feb 2003 12:03:02 +0000 (GMT)
|
|
Hi!
Try this for insertin data in your dataset.
SqlConnection myConnection;
// Create a connection to the SQL database
located on
// the local computer.
String insertCmd = "insert into Tables values
(@Field1,
@Field2)";
// Initialize the SqlCommand with the new SQL
string
// and the connection information.
SqlCommand myCommand = new SqlCommand(insertCmd,
myConnection);
// Create new parameters for the SqlCommand
object and
// initialize them to the input-form field
values.
myCommand.Parameters.Add(new
SqlParameter("@Field1",
SqlDbType.VarChar, 11));
myCommand.Parameters["@Field1"].Value
Field1.Value;
myCommand.Parameters.Add(new
SqlParameter("@Field1",
SqlDbType.VarChar, 40));
myCommand.Parameters["@Field1"].Value
Field2.Value;
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
________________________________________________________________________
Missed your favourite TV serial last night? Try the new, Yahoo! TV.
visit http://in.tv.yahoo.com
|
|
 |