944,184 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 13621
  • C# RSS
Nov 24th, 2006
0

SQL DataReader

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
newtoocsharp is offline Offline
3 posts
since Nov 2006
Nov 25th, 2006
0

Re: SQL DataReader

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;
}
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: SqlDataReader
Next Thread in C# Forum Timeline: Trying to obtain text from a file.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC