471,306 Members | 1,291 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

how to bind an array of data to a datagrid?

Hi all! I got an array of datarows after a select on a datatable, I want
to show the results in datagrid, but it doesnt work, do i have to create
a dataview? Please help me out thank you IRNBRU

*** Sent via Developersdex http://www.developersdex.com ***
Feb 18 '06 #1
1 1319
Hi Irnbru,

You should use DataView. here is some sample code for you.

SqlCommand cmd = new SqlCommand();

SqlConnection con = new SqlConnection();

DataSet ds = new DataSet();
SqlDataAdapter adap = new SqlDataAdapter();

SqlDataReader rdr ;
con.ConnectionString = @"server=.;database=AdventureWorks;uid=sa;pwd=s a";

con.Open();

cmd.Connection = con;

cmd.CommandType = CommandType.Text;

cmd.CommandText = @"select LocationID,Name as LocNAme from
Production.Location";

adap.SelectCommand = cmd;

adap.Fill(ds, "ER");

DataRow[] dr = ds.Tables[0].Select();
dataGrid1.DataSource = dr[0].Table.DefaultView;

vinu


"irnbru irnbru" <le*********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi all! I got an array of datarows after a select on a datatable, I want
to show the results in datagrid, but it doesnt work, do i have to create
a dataview? Please help me out thank you IRNBRU

*** Sent via Developersdex http://www.developersdex.com ***

Feb 19 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Michael Whittaker | last post: by
6 posts views Thread by Ricardo Luceac | last post: by
reply views Thread by Katit | last post: by
8 posts views Thread by iluvatar | last post: by
2 posts views Thread by Taha | last post: by
reply views Thread by =?Utf-8?B?Q2hyaXN0aWFuIEJhaG5zZW4=?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.