Click here to Skip to main content
15,894,410 members
Home / Discussions / C#
   

C#

 
QuestionGracefully shutting down threads Pin
User 665817-Jan-06 11:44
User 665817-Jan-06 11:44 
AnswerRe: Gracefully shutting down threads Pin
CWIZO17-Jan-06 21:15
CWIZO17-Jan-06 21:15 
GeneralRe: Gracefully shutting down threads Pin
User 665818-Jan-06 2:12
User 665818-Jan-06 2:12 
GeneralRe: Gracefully shutting down threads Pin
CWIZO18-Jan-06 3:01
CWIZO18-Jan-06 3:01 
QuestionVS 2005 UK edition Pin
pieterman17-Jan-06 11:44
pieterman17-Jan-06 11:44 
AnswerRe: VS 2005 UK edition Pin
Christian Graus17-Jan-06 14:03
protectorChristian Graus17-Jan-06 14:03 
GeneralRe: VS 2005 UK edition Pin
pieterman18-Jan-06 7:03
pieterman18-Jan-06 7:03 
QuestionTry/Catch Variable Scoping Pin
RobertF5717-Jan-06 11:34
RobertF5717-Jan-06 11:34 
Subject: Try/Catch Variable Scoping

If I try to compile the following code in .NET 1.1, I get the error "Use of unassigned local variable 'rdr'" when I'm assigning a value to intSurveyQuestionOrdinal. I understand that the try block's brace is creating a separate scope. However, I tried to get around that by declaring rdr at the top of the method. Why doesn't this work? Confused | :confused:

Thanks.


protected int GetSurveyQuestion()
{
SqlDataReader rdr;

SqlConnection connection = new SqlConnection(AppConfig.GetDbConnectionString(Convert.ToString(Request.Url)));
connection.Open();

SqlCommand command = new SqlCommand("usp_SEL_SurveyQuestion", connection);
command.CommandType = CommandType.StoredProcedure;

try
{
rdr = command.ExecuteReader();
}
catch(Exception exc)
{
pnlQuestion.Visible = false;
pnlError.Visible = true;
lblAdminPageHeader1.Text = "Application Error";
lblAdminPrompt1.Text = "The SELECT database operation failed: " + exc.Message;
rdr.Close();
connection.Close();
}

int intSurveyQuestionOrdinal = rdr.GetOrdinal("SurveyQuestion"); // <--- ERROR HAPPENS HERE
int intSurveyIDOrdinal = rdr.GetOrdinal("SurveyID");
while (rdr.Read())
{
strSurveyQuestion = rdr.GetString(intSurveyQuestionOrdinal);
intSurveyID = rdr.GetInt32(intSurveyIDOrdinal);
}

rdr.Close();
connection.Close();
return intSurveyID;
}
AnswerRe: Try/Catch Variable Scoping Pin
Guffa17-Jan-06 11:50
Guffa17-Jan-06 11:50 
GeneralRe: Try/Catch Variable Scoping Pin
RobertF5717-Jan-06 11:55
RobertF5717-Jan-06 11:55 
AnswerRe: Try/Catch Variable Scoping Pin
Guffa17-Jan-06 12:14
Guffa17-Jan-06 12:14 
GeneralRe: Try/Catch Variable Scoping Pin
RobertF5717-Jan-06 12:38
RobertF5717-Jan-06 12:38 
QuestionSetup Project - Getting the user selected install directory Pin
dotnetprgrmmr17-Jan-06 11:28
dotnetprgrmmr17-Jan-06 11:28 
AnswerRe: Setup Project - Getting the user selected install directory Pin
Sasuko17-Jan-06 11:48
Sasuko17-Jan-06 11:48 
GeneralRe: Setup Project - Getting the user selected install directory Pin
dotnetprgrmmr17-Jan-06 12:00
dotnetprgrmmr17-Jan-06 12:00 
GeneralRe: Setup Project - Getting the user selected install directory Pin
Sasuko17-Jan-06 12:42
Sasuko17-Jan-06 12:42 
GeneralRe: Setup Project - Getting the user selected install directory Pin
dotnetprgrmmr18-Jan-06 6:09
dotnetprgrmmr18-Jan-06 6:09 
QuestionDatabase VS direct update Pin
Sasuko17-Jan-06 11:19
Sasuko17-Jan-06 11:19 
AnswerRe: Database VS direct update Pin
Guffa17-Jan-06 11:54
Guffa17-Jan-06 11:54 
GeneralRe: Database VS direct update Pin
Sasuko17-Jan-06 12:14
Sasuko17-Jan-06 12:14 
GeneralRe: Database VS direct update Pin
Dave Kreskowiak17-Jan-06 17:25
mveDave Kreskowiak17-Jan-06 17:25 
AnswerRe: Database VS direct update Pin
Guffa19-Jan-06 23:03
Guffa19-Jan-06 23:03 
QuestionMaking the panel invisible?? Pin
VPMahank17-Jan-06 11:12
VPMahank17-Jan-06 11:12 
AnswerRe: Making the panel invisible?? Pin
CWIZO17-Jan-06 21:11
CWIZO17-Jan-06 21:11 
GeneralRe: Making the panel invisible?? Pin
VPMahank18-Jan-06 1:32
VPMahank18-Jan-06 1:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.