|
-
Nov 15th, 2004, 11:20 PM
#1
Thread Starter
Fanatic Member
[Solved] Use of unassigned local variable "dr"
Why is she (C#) treating "dr" as an unassigned local variable? Or am I missing something?
Code:
natureofcollections n=new natureofcollections();
SqlDataReader dr;
try
{
monkey.sql.sqlconnection.openconnection(cn);
dr=new monkey.sql.sqlcommand("selectallnatureofcollections",cn).executereader();
while(dr.Read())
{
n.add(new natureofcollection(dr[0].ToString(),
dr[1].ToString(),
dr[2].ToString()));
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
dr.Close();
monkey.sql.sqlconnection.closeconnection(cn);
}
return n;
Thank you.
Last edited by brown monkey; Nov 16th, 2004 at 04:12 AM.
-
Nov 16th, 2004, 04:04 AM
#2
if monkey.sql.sqlconnection.openconnection(cn); fails then dr will never get initialised try
Code:
SqlDataReader dr = null;
-
Nov 16th, 2004, 04:11 AM
#3
Thread Starter
Fanatic Member
Kinda strict, huh... I thank you.
Once again, the day has been save... Thanks to the DeadEyes
Last edited by brown monkey; Nov 16th, 2004 at 04:15 AM.
-
Nov 16th, 2004, 04:33 AM
#4
no problem
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|