how to bind an array of data to a datagrid?

I

irnbru irnbru

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
 
V

vinu

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=sa";

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top