SQL DataReader

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2006
Posts: 3
Reputation: newtoocsharp is an unknown quantity at this point 
Solved Threads: 0
newtoocsharp newtoocsharp is offline Offline
Newbie Poster

SQL DataReader

 
0
  #1
Nov 24th, 2006
I have successfully got the data reader connected but i cannot figure out how to write the values to an array or variables on a windows form created in Visual C# Express edition all examples use the console.
Can someone show me an example of how to write these values to an array so that i can use that as my starting point to initialize the values on the windows form? This is really new to me and a little confusing.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: SQL DataReader

 
0
  #2
Nov 25th, 2006
Maybe this will shed some light on the subject.

I create an array of object[] that is populated by the current row when using the GetValues method of the SQLDataReader.
I have a set of constants to identify specif columns from the row, however you can use quoted column names instead.
A nice little trick is to save the entire row into the TAG property of my treeview as shown below. while ...Read() is the same thing as while not data.eof.

Have fun,
Jerry


SqlDataReader ogRdr = command.ExecuteReader();
while (ogRdr.Read())
{
Object[] values = new Object[ogRdr.FieldCount];
ogRdr.GetValues(values);
node = treeOperGroup.Nodes.Add((string)ogRdr[COL_OPERGROUPNAME]);
node.Tag = values;
}
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC