Click here to Skip to main content
15,915,164 members
Home / Discussions / Database
   

Database

 
QuestionINSERT INTO and SELECT statement... pls help urgently.. Pin
For_IT12-Jul-06 0:19
For_IT12-Jul-06 0:19 
AnswerRe: INSERT INTO and SELECT statement... pls help urgently.. Pin
VK-Cadec12-Jul-06 9:53
VK-Cadec12-Jul-06 9:53 
QuestionData Access Application Block Pin
Brendan Vogt11-Jul-06 21:22
Brendan Vogt11-Jul-06 21:22 
AnswerRe: Data Access Application Block Pin
kumarprabhakar7412-Jul-06 0:25
kumarprabhakar7412-Jul-06 0:25 
QuestionThe using block Pin
Brendan Vogt11-Jul-06 21:12
Brendan Vogt11-Jul-06 21:12 
AnswerRe: The using block Pin
ekhorutomwen11-Jul-06 22:49
ekhorutomwen11-Jul-06 22:49 
QuestionRe: The using block Pin
Brendan Vogt11-Jul-06 23:08
Brendan Vogt11-Jul-06 23:08 
AnswerRe: The using block [modified] Pin
ekhorutomwen11-Jul-06 23:30
ekhorutomwen11-Jul-06 23:30 
Hi i am not completely sure what you are trying to do but i would have implemented your code this way:

try
{
using (dbCommand = db.GetStoredProcCommand("sp_GetAllCars"))
{
rdr = dbCommand.ExecuteReader(); //db.ExecuteReader(dbCommand);

while (rdr.Read())
{
Car objCar = new Car();
objCar.ID = rdr.GetInt32(0); // Required
objCar.Name = rdr.GetString(1); // Required

// Add Car instance to array
carList.Add(objCar);
}
// Close the reader object
rdr.Close();
}
}
catch (SqlException ex)
{
HandleSQLError(ex, "sp_GetAllCars");
}
finally
{

}

you need to close rdr since it has exclusive access to the connection and without closing it, you can not use the underlying connection. at the end of the using, the dbCommand will be release. what i think you might need in the finally is to close the underlying connection. but that also depends on if you are not using the connection else where within the function after the finally block. i generally don't dispose my connections. but i use the Close() option since this will return the connection to the pool rather than releasing all its resources which happens with dispose().


-- modified at 5:31 Wednesday 12th July, 2006
GeneralRe: The using block Pin
Brendan Vogt11-Jul-06 23:47
Brendan Vogt11-Jul-06 23:47 
AnswerRe: The using block Pin
Kevin McFarlane12-Jul-06 0:22
Kevin McFarlane12-Jul-06 0:22 
QuestionChecking for an Existing record when Updating Pin
Brendan Vogt11-Jul-06 21:08
Brendan Vogt11-Jul-06 21:08 
AnswerRe: Checking for an Existing record when Updating Pin
kumarprabhakar7412-Jul-06 0:21
kumarprabhakar7412-Jul-06 0:21 
QuestionUpdate statement Pin
angelagke11-Jul-06 18:23
angelagke11-Jul-06 18:23 
AnswerRe: Update statement Pin
Dinuj Nath11-Jul-06 20:51
Dinuj Nath11-Jul-06 20:51 
GeneralRe: Update statement Pin
angelagke11-Jul-06 21:37
angelagke11-Jul-06 21:37 
GeneralRe: Update statement Pin
VK-Cadec12-Jul-06 10:01
VK-Cadec12-Jul-06 10:01 
GeneralRe: Update statement Pin
angelagke13-Jul-06 2:07
angelagke13-Jul-06 2:07 
QuestionConnectionString works for VB6/VBNET/VBNET2003 for SQL SERVER but not for VBNET2005 SQL SERVER only local Pin
Serpiente11-Jul-06 15:16
Serpiente11-Jul-06 15:16 
QuestionOutput parameter in stored procedure Pin
leckey11-Jul-06 9:27
leckey11-Jul-06 9:27 
AnswerRe: Output parameter in stored procedure Pin
nguyenvhn11-Jul-06 22:38
nguyenvhn11-Jul-06 22:38 
GeneralRe: Output parameter in stored procedure Pin
leckey12-Jul-06 3:13
leckey12-Jul-06 3:13 
QuestionDB Connection Failure using C# Pin
Cadence2.011-Jul-06 9:03
Cadence2.011-Jul-06 9:03 
AnswerRe: DB Connection Failure using C# Pin
god_bless_the_world11-Jul-06 11:22
god_bless_the_world11-Jul-06 11:22 
GeneralRe: DB Connection Failure using C# Pin
Cadence2.011-Jul-06 11:47
Cadence2.011-Jul-06 11:47 
QuestionStored Procedures Pin
HRiazi11-Jul-06 6:50
HRiazi11-Jul-06 6:50 

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.