escap3
July 18th, 2009, 03:25 PM
hi there, I'm writing an windows application that receive money from customer, it has three value in database,
firstPayment : this is the first field that customer give to program as first payment
secondPayment : this is the second field that cumstomer give to program as second payment .
thirdPayment : this is the last payment that customer give to application ...
Ok, now I want to show values that stored in these fields in seperate text boxes ..., textbox1 : for presenting the value of firstPayment, textbox2 : presenting the value of secondPayment and so on
I've been used SqlDataReader class for this kind of thing, when I started filling the firstPayment and secondPayment by clicking on the button I've been recieved the answer, textbox1 has been shown firstPayment value, and secondPayment has been shown in the textbox2 , but when the thirdPayment fills things changed exotic , now when thirdPayment has value, whenever I press Button it must show three value into three textboxes, but an error has occured,
" and attempt to read when no data is present "
I don't know what's the matter, I checked different kind of codes but I got no answer,
here's my code,
private void button6_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection())
{
using (SqlCommand cmd = new SqlCommand())
{
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ClinicDB.mdf;Integrated Security=True;User Instance=True";
cmd.CommandText = "SELECT firstPayment,secondPayment,thirdPayment FROM financialT where name = @name and family = @family";
cmd.Connection = con;
cmd.Parameters.AddWithValue("@name", txtName.Text);
cmd.Parameters.AddWithValue("@family", txtFamily.Text);
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
if (sdr != null)
{
sdr.Read();
textBox1.Text = sdr.GetValue(0).ToString(); /* == DBNull.Value ? "" : sdr.GetValue(0).ToString();*/
textBox2.Text = sdr.GetValue(1).ToString();/* == DBNull.Value ? "" : sdr.GetValue(1).ToString() ;*/
textBox4.Text = sdr.GetValue(2).ToString();/* == DBNull.Value ? "" : sdr.GetValue(2).ToString(); */
}
}
}
}
}
can anyone help me for solving this problem !?
thanks alot ...
firstPayment : this is the first field that customer give to program as first payment
secondPayment : this is the second field that cumstomer give to program as second payment .
thirdPayment : this is the last payment that customer give to application ...
Ok, now I want to show values that stored in these fields in seperate text boxes ..., textbox1 : for presenting the value of firstPayment, textbox2 : presenting the value of secondPayment and so on
I've been used SqlDataReader class for this kind of thing, when I started filling the firstPayment and secondPayment by clicking on the button I've been recieved the answer, textbox1 has been shown firstPayment value, and secondPayment has been shown in the textbox2 , but when the thirdPayment fills things changed exotic , now when thirdPayment has value, whenever I press Button it must show three value into three textboxes, but an error has occured,
" and attempt to read when no data is present "
I don't know what's the matter, I checked different kind of codes but I got no answer,
here's my code,
private void button6_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection())
{
using (SqlCommand cmd = new SqlCommand())
{
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ClinicDB.mdf;Integrated Security=True;User Instance=True";
cmd.CommandText = "SELECT firstPayment,secondPayment,thirdPayment FROM financialT where name = @name and family = @family";
cmd.Connection = con;
cmd.Parameters.AddWithValue("@name", txtName.Text);
cmd.Parameters.AddWithValue("@family", txtFamily.Text);
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
if (sdr != null)
{
sdr.Read();
textBox1.Text = sdr.GetValue(0).ToString(); /* == DBNull.Value ? "" : sdr.GetValue(0).ToString();*/
textBox2.Text = sdr.GetValue(1).ToString();/* == DBNull.Value ? "" : sdr.GetValue(1).ToString() ;*/
textBox4.Text = sdr.GetValue(2).ToString();/* == DBNull.Value ? "" : sdr.GetValue(2).ToString(); */
}
}
}
}
}
can anyone help me for solving this problem !?
thanks alot ...