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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Soft CornerPosted Apr 12, 2011, 5:30 AM
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();
}
krishnaPosted Apr 12, 2011, 12:04 PM
Thankx a lot!!! :).it is working.i have given space in the column name in the table definition.
krishnaPosted Apr 12, 2011, 12:00 PM
Thankx a lot!!! :).it is working
ArshadPosted Apr 12, 2011, 5:19 AM
You are using the cmd.ExecuteNonQuery(); with datareader, you should use the cmd.ExecuteReader();.
Regards,
Arshad.