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 TrivediRank #16 · 50.3K reputationPosted Oct 2, 2013, 9:15 PM EDT
can you please check what the value in dr["status"] ?
also try
if (dr["status"].ToString().Trim() == "Sold")
{
// do you code here...
}
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 2, 2013, 7:52 PM EDT
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.
ta mu198 reputationPosted Oct 2, 2013, 8:39 PM EDT
befor it was working fine but now i dont know what hapend
Sunny SharmaRank #223 · 11.1K reputationPosted Oct 2, 2013, 9:18 PM EDT
ta mu198 reputationPosted Oct 2, 2013, 9:25 PM EDT
Sunny SharmaRank #223 · 11.1K reputationPosted Oct 2, 2013, 9:29 PM EDT
Trim() removes the trailing and following spaces from a string.