Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
AnswerRe: Code in c# Pin
Dave Kreskowiak9-Dec-18 5:13
mveDave Kreskowiak9-Dec-18 5:13 
AnswerRe: Code in c# Pin
Kevin Marois10-Dec-18 8:07
professionalKevin Marois10-Dec-18 8:07 
Questionhow to bind all text filed with dropdownlist data selection in kendo grid,give any example Pin
Member 115679596-Dec-18 1:25
Member 115679596-Dec-18 1:25 
AnswerRe: how to bind all text filed with dropdownlist data selection in kendo grid,give any example Pin
OriginalGriff6-Dec-18 2:35
mveOriginalGriff6-Dec-18 2:35 
GeneralRe: how to bind all text filed with dropdownlist data selection in kendo grid,give any example Pin
Richard Andrew x648-Dec-18 5:32
professionalRichard Andrew x648-Dec-18 5:32 
QuestionThere is already an open DataReader associated with this Command which must be closed first. Pin
govind_nanna5-Dec-18 19:45
govind_nanna5-Dec-18 19:45 
AnswerRe: There is already an open DataReader associated with this Command which must be closed first. Pin
Pete O'Hanlon5-Dec-18 20:54
mvePete O'Hanlon5-Dec-18 20:54 
AnswerRe: There is already an open DataReader associated with this Command which must be closed first. Pin
OriginalGriff5-Dec-18 21:30
mveOriginalGriff5-Dec-18 21:30 
To add to Pete's excellent advice, the best way to do this is to put the construction of all database related items (Connections, Commands, Adapters, ...) inside a using block. That way, when the item goes out of scope for whatever reason (even if there is a failure) the object is automatically closed and disposed.

Do that, and you will never have the problem again, as well as not hogging scarce resources.

C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("SELECT Id, description FROM myTable", con))
        {
        using (SqlDataReader reader = cmd.ExecuteReader())
            {
            while (reader.Read())
                {
                int id = (int) reader["Id"];
                string desc = (string) reader["description"];
                Console.WriteLine("ID: {0}\n    {1}", id, desc);
                }
            }
        }
    }

Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

JokeRe: There is already an open DataReader associated with this Command which must be closed first. Pin
Richard Deeming6-Dec-18 8:01
mveRichard Deeming6-Dec-18 8:01 
GeneralRe: There is already an open DataReader associated with this Command which must be closed first. Pin
OriginalGriff6-Dec-18 20:44
mveOriginalGriff6-Dec-18 20:44 
GeneralRe: There is already an open DataReader associated with this Command which must be closed first. Pin
Richard MacCutchan6-Dec-18 23:21
mveRichard MacCutchan6-Dec-18 23:21 
GeneralRe: There is already an open DataReader associated with this Command which must be closed first. Pin
OriginalGriff6-Dec-18 23:31
mveOriginalGriff6-Dec-18 23:31 
GeneralRe: There is already an open DataReader associated with this Command which must be closed first. Pin
Pete O'Hanlon7-Dec-18 1:17
mvePete O'Hanlon7-Dec-18 1:17 
GeneralRe: There is already an open DataReader associated with this Command which must be closed first. Pin
OriginalGriff7-Dec-18 1:40
mveOriginalGriff7-Dec-18 1:40 
QuestionDynamic alignment of winform controls Pin
george49864-Dec-18 17:52
professionalgeorge49864-Dec-18 17:52 
AnswerRe: Dynamic alignment of winform controls Pin
Dave Kreskowiak4-Dec-18 17:56
mveDave Kreskowiak4-Dec-18 17:56 
GeneralRe: Dynamic alignment of winform controls Pin
george49864-Dec-18 18:38
professionalgeorge49864-Dec-18 18:38 
AnswerRe: Dynamic alignment of winform controls Pin
Eddy Vluggen5-Dec-18 2:03
professionalEddy Vluggen5-Dec-18 2:03 
AnswerRe: Dynamic alignment of winform controls Pin
BillWoodruff5-Dec-18 14:44
professionalBillWoodruff5-Dec-18 14:44 
QuestionReflection - from Type to Class (not instance of class) Pin
devvvy4-Dec-18 13:51
devvvy4-Dec-18 13:51 
AnswerRe: Reflection - from Type to Class (not instance of class) Pin
OriginalGriff4-Dec-18 21:31
mveOriginalGriff4-Dec-18 21:31 
AnswerRe: Reflection - from Type to Class (not instance of class) Pin
F-ES Sitecore5-Dec-18 1:02
professionalF-ES Sitecore5-Dec-18 1:02 
AnswerRe: Reflection - from Type to Class (not instance of class) Pin
Richard Deeming5-Dec-18 9:09
mveRichard Deeming5-Dec-18 9:09 
QuestionCode refactoring.. Pin
Simon_Whale4-Dec-18 2:49
Simon_Whale4-Dec-18 2:49 
AnswerRe: Code refactoring.. Pin
dan!sh 4-Dec-18 3:29
professional dan!sh 4-Dec-18 3:29 

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.