Friday, April 3, 2009

Typed DataSet

Typed DataSet :-
Typed DataSets have all the functionality of DataSets, Typed DataSets directly inherit from the

DataSet classes. Some additional code generated by .NET Framework tools gives all the additional benefits of

Typed DataSets. Furthermore, you can access table and columns by name instead of having to use collection-based

methods with DataSets

-> Typed DataSets check types at compile time it also konwn as This is known as type-safe access
-> automatically complete lines while typing rather the describe each time column name.
Hi how to use Typed Data set
/ * 1-> add new item set dataset. give a name to it delete which coneection is provide by default with it.
* 2-> right click on dataset and add a new table.
* 3-> right click on table and add column which will filled by code.
* 4-> code snipp is bellow.
* note the column name of select command and dataset.xss shuld be same
*/
SqlConnection cn = new SqlConnection(@"Data Source=xxxxxx\VER2005;Initial Catalog=PUBS;Persist Security Info=True;User ID=xxx;Password=xxxx");
SqlCommand cmd = new SqlCommand("SELECT bookRecord.* FROM bookRecord", cn); SqlDataAdapter da = new SqlDataAdapter(cmd);
dsProducts tds = new dsProducts();
da.Fill(tds, tds.Tables[0].TableName);

foreach (DataRow oOrderRow in tds.DataTable1.Rows )
{ Response.Write ("BookID = " + oOrderRow["bookid"].ToString()); }
string ss = tds.DataTable1.Rows[0]["bookid"].ToString();

string ss2 = t ds.DataTable1.Rows[1]["bookid"].ToString();

Thanks
HelpOnDesck Team

No comments: