Richard1996 Richard1996 -4 years ago 90
ASP.NET (C#) Question

How to store a variable from a reader outside of a while statement

I have the following while statement:

while (reader.Read()) {string bin_type = reader.GetString(0);}

Because this is in a while i cannot access this variable after it has been stored. How can I store the value from a reader so that it can be used outside of the while statement?

Answer Source

Use global variable For exp....

string bin_type=string.Empty;
while (reader.Read()) {bin_type += reader.GetString(0);}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download