AccountNo-int type with IsIncrement-true
Name-varchar(20)
Age-int
Balance-float
The code is Uploaded in a zip file
Thank You
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Soft CornerRank #1,221 · 1.5K reputationPosted Apr 12, 2011, 1:30 AM EDT
Krishna, check with DB table , might be you have different name for AccountNo coloumn bcz in your code there is some minor changes only which is i have done ,rest your code works fine,
string sqlconn = "Data Source=.\\SQLEXPRESS;Initial Catalog=bank;Integrated Security=True";
SqlConnection conn = new SqlConnection(sqlconn);
try
{
SqlDataReader dr;
conn.Open();
string commandtext = "SELECT AccountNo,Balance FROM Bank_Account1";
SqlCommand cmd = new SqlCommand(commandtext, conn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
MessageBox.Show(dr[0].ToString());
MessageBox.Show(dr[1].ToString());
}
dr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
conn.Close();
}
ArshadRank #2,492 · 564 reputationPosted Apr 12, 2011, 1:19 AM EDT
You are using the cmd.ExecuteNonQuery(); with datareader, you should use the cmd.ExecuteReader();.
Regards,
Arshad.
krishna5 reputationPosted Apr 12, 2011, 8:00 AM EDT
Thankx a lot!!! :).it is working
krishna5 reputationPosted Apr 12, 2011, 8:04 AM EDT
Thankx a lot!!! :).it is working.i have given space in the column name in the table definition.