How to create typed Dataset
1>First create a table with sql server enterprise manager
Say we have created a table with name member which have a following
filed :=>PKID(Int),MemberID(bigint),Name(Varchar),Salary(float),
SalaryType(bit).
2>Enter few records into the table.
3>Now open the visual studio .net editor.
4>Craete a new asp.net web site.
5>In Solution Explorer, right-click to add a new item, and select
DataSet. Give it the name MemberDataSet.xsd. Visual Studio will
recommend placing the DataSet file inside the App_Code folder,
which you should allow it to do for you.
6>Now cancel the connection interface which will open as default.
7>Open the server explorer.drag table into the design window.
8>Now right ckick on the TableAdaptor=>click on configure.
9>Customize the query accordingly=>Click Next=>Specify the Method name
=>Click next=>Click Next.
10>Now come to the code behind and add the following code.
The way out in which not need to create any connection.
TypedDatasetTableAdapters.MemberTableAdapter objTA = new TypedDatasetTableAdapters.MemberTableAdapter();
//TypedDataset.MemberDataTable objT = objTA.GetData(2,false);//Fetch data with parameter.
TypedDataset.MemberDataTable objT = objTA.GetDataByAll();
rptTest.DataSource = objT;
rptTest.DataBind();
the way out in which need to create connection.
string strConnectionString = "user id=sa;password=sa;data source=localhost;initial catalog=rnd;";
SqlConnection objConne = new SqlConnection(strConnectionString);
SqlCommand objComm = new SqlCommand("Select PKID,Name,MemberID,Salary from Member", objConne);
SqlDataAdapter objAdap = new SqlDataAdapter(objComm);
//objDS.Member[0].Name = "Priyabrata";
objAdap.Fill(objDS, "Member");
rptTest.DataSource = objDS.Tables["Member"].DefaultView;
rptTest.DataBind();
//Person Table first row name collumn
//objDS.Person[0].Name = 1;//It will generate compile time error.
Sunday, September 5, 2010
Subscribe to:
Post Comments (Atom)
.jpg)
0 comments:
Post a Comment