Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

Ranjith Kumar
More...


Forums » .NET » ASP.NET »

about dataadapter


Posted Date: 20 Sep 2008      Posted By:: samatha g     Member Level: Gold    Member Rank: 1275     Points: 1   Responses: 4



can i use dataadapter like this:

actually we always use cmd.executenonscalar() for returning a single row.
is there any way to use dataadapter with return 1 row.

i want for the below query:

cmd.commandtext="select count(*) from emp";
int i=Convert.toint32(cmd.ExecuteNonScalar());

instead of that:
i need to return that value to dataadapter,so that i can bind that value to a gridview(for creating rows in a gridview at runtime)

please help me soon...............




Responses

#297847    Author: Karthikeyan S      Member Level: Gold      Member Rank: 726     Date: 20/Sep/2008   Rating: 2 out of 52 out of 5     Points: 4

Hi,

Use ExecuteScalar function, Dataadapter and dataset to bind the value to gridview.

cmd.commandtext="select count(*) from emp";
SqlDataAdapter lda = new SqlDataAdapter(cmd);
DataSet lds = new DataSet();
lda.Fill(lds);

gv.DataSource = lds;
gv.DataBind();



 
#297850    Author: praveen      Member Level: Gold      Member Rank: 0     Date: 20/Sep/2008   Rating: 2 out of 52 out of 5     Points: 4

hi

SqlConnection con = new SqlConnection("ur databaseconnection");
SqlCommand cmd = new SqlCommand("Select * from student",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

GridView.DataSource = ds;
GridView.DataBind();


regards
praveen



 
#297949    Author: Bunty      Member Level: Gold      Member Rank: 15     Date: 21/Sep/2008   Rating: 2 out of 52 out of 5     Points: 4

Hi,

SQLConnection con=new SQLConnection("your connection string");

SQLCommand cmd=new SQLCommand("Select * from emp",con);

SQLDataAdapter ad=new SQLDataAdapter(cmd);

DataSet ds=new DataSet();

ad.Fill(ds,"e");

DataGrid1.DataSource=ds;

Regards
S.S.Bajoria


Thanks & Regards


Bunty

Expertise Dot Net On Earth






 
#298054    Author: nirmala      Member Level: Gold      Member Rank: 565     Date: 21/Sep/2008   Rating: 2 out of 52 out of 5     Points: 3

hai,

SqlDataAdapter da = new SqlDataAdapter("select * from station",conn);
DataSet ds = new DataSet();
da.Fill(ds);

gv.DataSource = ds;
gv.DataBind();



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : on gridview
Previous : How to write Update stored procedure
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.