I'm very new to C# but I need to save the results of two columns (balance & withdraw) from a SQL Server database table to C# variables. I have read that you should use SqlDataReader then other things are saying not to and use ExecuteScalar and I'm getting really confused with it all.
Here is the code I have to far. Any help is appreciated thanks.
private void subwithdraw_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=Student04\SQLEXPRESS;Initial Catalog=ATMdata;Integrated Security=True");
SqlCommand cmd = new SqlCommand("Command String", con);
SqlDataReader rdr = null;
try
{
using (var check_balance = con.CreateCommand())
using (var edit_balance = con.CreateCommand())
using (var edit_withdraw = con.CreateCommand())
{
check_balance.CommandText = @"select Balance, Withdraw
from Cust_details
Where Account_num ='" + show.AccNo + "' ";
}
}
}
BalanceandWithdrawcolumns?