private void textBox8_Validated(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("SELECT model,fram_no,status FROM add_stock WHERE engen_no='" + textBox8.Text + "'", my);
my.Open();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
if (dr["status"].ToString() == "Sold")
{
MessageBox.Show("This Bike Is Sold");
textBox8.Text = "";
}
if (dr["status"].ToString() == "Available")
{
textBox16.Text = dr["model"].ToString();
textBox9.Text = dr["fram_no"].ToString();
}
}
else
{ MessageBox.Show("NOT A VALID ENGINE NO");
textBox8.Text = "";}
my.Close();
}
no error in code when i enter invalid no error messag shown bt when enter correct one no messag is diplayed for sold and not woks available code wahts wrong
Loading
Jignesh TrivediPosted Oct 3, 2013, 1:15 AM
can you please check what the value in dr["status"] ?
also try
if (dr["status"].ToString().Trim() == "Sold")
{
// do you code here...
}
Sunny SharmaPosted Oct 3, 2013, 1:29 AM
Trim() removes the trailing and following spaces from a string.
ta muPosted Oct 3, 2013, 1:25 AM
Sunny SharmaPosted Oct 3, 2013, 1:18 AM
ta muPosted Oct 3, 2013, 12:39 AM
befor it was working fine but now i dont know what hapend
Jignesh TrivediPosted Oct 2, 2013, 11:52 PM
hi,
message "NOT A VALID ENGINE NO" comes when no engine no is found.
here it might possible if engine no is found but it status is not sold or available.
it also might possible there is space in database value....
check it.