Click here to Skip to main content
15,908,775 members
Home / Discussions / C#
   

C#

 
QuestionTry-Catch problem in C# console app Pin
Member 46458019-Sep-09 9:05
Member 46458019-Sep-09 9:05 
I have the following code snippet in a C# console application and am getting the following error in VS2008 on the last line (bool recExists = myReader.HasRows):

Error 2 Use of unassigned local variable 'myReader'

Here's the code:

           string sResponse;<br />
            SqlDataReader myReader;<br />
<br />
            // Check existence of tracking record<br />
<br />
            sQuery = "Select * from tracking where shipper_id = '" + sShipperId +<br />
                "' AND shipper_ack = '" + sShipperAck + "'";<br />
<br />
            myCommand1 = new SqlCommand(sQuery, conn);<br />
<br />
            try<br />
            {<br />
                myReader = myCommand1.ExecuteReader();<br />
            }<br />
            catch (Exception e2)<br />
            {<br />
                conn.Close();<br />
                conn.Dispose();<br />
<br />
                sResponse = e2.GetBaseException().ToString() + "   " + sQuery;<br />
              <br />
            }<br />
<br />
            bool recExists = myReader.HasRows;


I use this same identical code in a Windows Client app with no problems.

What am I missing????

Thanks,

Dave
AnswerRe: Try-Catch problem in C# console app Pin
Christian Graus9-Sep-09 9:15
protectorChristian Graus9-Sep-09 9:15 
AnswerRe: Try-Catch problem in C# console app Pin
harold aptroot9-Sep-09 9:19
harold aptroot9-Sep-09 9:19 
GeneralRe: Try-Catch problem in C# console app Pin
Member 46458019-Sep-09 9:27
Member 46458019-Sep-09 9:27 
GeneralRe: Try-Catch problem in C# console app Pin
harold aptroot9-Sep-09 9:28
harold aptroot9-Sep-09 9:28 
GeneralRe: Try-Catch problem in C# console app Pin
Christian Graus9-Sep-09 9:39
protectorChristian Graus9-Sep-09 9:39 
AnswerRe: Try-Catch problem in C# console app Pin
Zoki Manas9-Sep-09 20:46
Zoki Manas9-Sep-09 20:46 
AnswerRe: Try-Catch problem in C# console app Pin
carlecomm22-Sep-09 16:00
carlecomm22-Sep-09 16:00 
QuestionPowerpoint using c# Pin
Vijay Mudunuri9-Sep-09 7:59
Vijay Mudunuri9-Sep-09 7:59 
AnswerRe: Powerpoint using c# Pin
Manas Bhardwaj9-Sep-09 8:30
professionalManas Bhardwaj9-Sep-09 8:30 
GeneralRe: Powerpoint using c# Pin
Vijay Mudunuri9-Sep-09 8:47
Vijay Mudunuri9-Sep-09 8:47 
AnswerRe: Powerpoint using c# Pin
Christian Graus9-Sep-09 9:16
protectorChristian Graus9-Sep-09 9:16 
QuestionFileSystemWatcher doesnt seem to be working on Win7 Pin
Gareth H9-Sep-09 6:34
Gareth H9-Sep-09 6:34 
AnswerRe: FileSystemWatcher doesnt seem to be working on Win7 Pin
stancrm9-Sep-09 8:54
stancrm9-Sep-09 8:54 
GeneralRe: FileSystemWatcher doesnt seem to be working on Win7 Pin
Gareth H9-Sep-09 22:24
Gareth H9-Sep-09 22:24 
AnswerRe: FileSystemWatcher doesnt seem to be working on Win7 Pin
Jacobb Michael9-Sep-09 22:39
Jacobb Michael9-Sep-09 22:39 
GeneralRe: FileSystemWatcher doesnt seem to be working on Win7 Pin
Gareth H9-Sep-09 22:43
Gareth H9-Sep-09 22:43 
GeneralRe: FileSystemWatcher doesnt seem to be working on Win7 Pin
Jacobb Michael10-Sep-09 1:19
Jacobb Michael10-Sep-09 1:19 
Questionget rid of advertised shortcut Pin
Piratenwichtl20009-Sep-09 5:25
Piratenwichtl20009-Sep-09 5:25 
AnswerRe: get rid of advertised shortcut Pin
Dave Kreskowiak9-Sep-09 6:25
mveDave Kreskowiak9-Sep-09 6:25 
QuestionExcel 2000 vs Excel 2007 Pin
jashimu9-Sep-09 3:50
jashimu9-Sep-09 3:50 
AnswerRe: Excel 2000 vs Excel 2007 Pin
Not Active9-Sep-09 4:32
mentorNot Active9-Sep-09 4:32 
GeneralRe: Excel 2000 vs Excel 2007 Pin
jashimu9-Sep-09 5:29
jashimu9-Sep-09 5:29 
GeneralRe: Excel 2000 vs Excel 2007 Pin
DaveyM699-Sep-09 5:35
professionalDaveyM699-Sep-09 5:35 
GeneralRe: Excel 2000 vs Excel 2007 Pin
dan!sh 9-Sep-09 6:23
professional dan!sh 9-Sep-09 6:23 

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.