Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to get one row record with SqlCommand. After data reader reading, I want to update LastLoginDate. But it fails. How can I update records in drf.Read() block.

SqlCommand kf = db.getCommand("SELECT Name FROM Members WHERE ID=1");
SqlDataReader drf = kf.ExecuteReader();
if (drf.Read())
{
    txtName = drf["Name"].ToString();

    using (SqlCommand kf2 = db.getCommand("UPDATE Members SET LastLogin=getdate() WHERE ID=@id"))
    {
        kf2.Parameters.AddWithValue("@id", 1);
        int s = kf2.ExecuteNonQuery();
    }
}
share|improve this question
    
Any exception inner message? –  Yagiz Ozturk Nov 21 '13 at 19:28
    
What do you mean by 'it fails'? Your debugger is your best friend here... –  Brian Nov 21 '13 at 19:38
    
Have a look at lamahashim.blogspot.com/2010/04/… –  Yagiz Ozturk Nov 21 '13 at 19:42
    
i looked back again my question. i solved this issue with connection parameter 'MultipleActiveResults=true' in connectionstring. But it is affecting Performance when i compared false value. @YagizOzturk i have multiple SqlCommand. And they use same connection. DataReader doesn't permit that. –  Cem 21 hours ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.