Hello!
I have created a local database in Visual Studio 2010 and a web application which interracts with it. I have a text box in which i write a date (delivery date, for example) and a search button to display all the information about an invoice having the delivery date i mention in the text field. Here is the code i wrote:
I don't get any error, but i receive te message from the else branch "No items were found!". So the sql command doesn' execute at all. Is it because of the sql part or did i miss something else?
I have created a local database in Visual Studio 2010 and a web application which interracts with it. I have a text box in which i write a date (delivery date, for example) and a search button to display all the information about an invoice having the delivery date i mention in the text field. Here is the code i wrote:
C#:
protected void btnCauta_FacturaLivrare(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=JOHN-PC\SQLEXPRESS;Initial Catalog=subiect1;Integrated Security=True");
try
{
con.Open();
SqlCommand cmd = new SqlCommand("select Data_Livrare from Factura where (Data_Livrare = @Data_Livrare)", con);
cmd.Parameters.AddWithValue("@Data_Livrare", txtData.Text);
if (cmd.ExecuteNonQuery() == 1)
{
Label3.Text = "Yes!";
}
else
{
Label3.Text = "No items were found!";
}
}
catch (Exception ex)
{
Label3.Text = "Error --> " + ex.Message;
}
finally
{
con.Close();
}
}
I don't get any error, but i receive te message from the else branch "No items were found!". So the sql command doesn' execute at all. Is it because of the sql part or did i miss something else?