Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Grid, Multiple Data Sets? 1

Status
Not open for further replies.

stathread

Programmer
Jan 17, 2006
38
US
Ok I will give the down low of what im trying to accomplish.

I can view data with the datagrid like anyone else, but what im trying to do is loop through a listbox of server names and fill just one datagrid with the results from each server.

For example,

server will be each server in the listbox.

String sconnect = "Server=" + server + ";DataBase=msdb;Integrated Security=SSPI";

select * from SYSTABLE

Now as I run through the listbox of servers I will retrieve different results in which id like to place in 1 datagrid

All column names ARE the same.

SERVER COLUMN1 COLUMN2 COLUMN3
SQL1 Bob Smith Oakwood Florida
SQL2 Brian Kite Oakland Georgia
SQL3 Frank Sinatra Spider Ohio


Thank you for all of you help.
 
You could just make a DataTable. Fill the datatable with the data that you want, and then just make the datatable the source for the datagrid. The datatable has much less overhead.

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
how would I go about doing this, this is what im working on so far.

rsadapter.Fill(sqldataset, rsconnect);

dataGrid1.DataSource = sqldataset.Tables[rsconnect];

dataTable = sqldataset.Tables[dataTable] + sqldataset.Tables[a]; //This part is not working

I am trying to add data to the datatable
 
Here is what I would do:

Code:
			// you have a set number of columns 
			// create a datatable and define them
			DataTable dt = new DataTable("stathread");

			dt.Columns.Add("SERVER");
			dt.Columns.Add("COLUMN1");
			dt.Columns.Add("COLUMN2");
			dt.Columns.Add("COLUMN3");

			// get your server data out of the list box
			// DO SOME STUFF HERE
			
			// make a loop that cycles through the list of returned servers
			for (int i = 0; i < returned_server_count; i++)
			{
				// define the array that will hold the values for each row
				string[] theRow = new string[4];
			
				// get the server name from your listbox at position i,
				// assign it to the first item in the array
				theRow[0] = "your retrieved server name";

				// do your stuff to get the dynamic data
				// based on the value you retrieved above
				// assign it to the other array positions
				theRow[1] = "Stuff you got for col 1";
				theRow[2] = "Stuff you got for col 2";
				theRow[3] = "Stuff you got for col 3";

				// make a row based on the datatable schema
				DataRow dr = dt.NewRow();

				// assign the array to the row
				dr.ItemArray = theRow;

				// add the row to the table
				dt.Rows.Add(dr);
			}

			// set the datasource
			dataGrid1.DataSource = dt;

I wouldn't use a dataadapter or dataset at all. They have way too much overhead for what you need to do. Use a SqlCommand, SqlConnection, and then a SqlDataReader.

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Thanks for all of your help.

I however took a diff approach and cloned & copied the data to a new datatable then viewed it.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top