vendredi 31 juillet 2015

What is wrong with my SQL Server query as it is not inserting the data in to table [on hold]

Here is my code

private void productsavebtn_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection("Data Source=SAJJAD-PC;Initial Catalog=hotel;Integrated Security=True;");

    try
    {
        con.Open();
        label1.Text = "Connection Successful";

        SqlCommand cmd1 = con.CreateCommand();
        cmd1.CommandText =( "INSERT INTO product (productname , productprice) VALUES ('" + productnametxtbox.Text + "','" + productpricetxtbox.Text + "')");

        try
        {
            cmd1.ExecuteNonQuery();
            label1.Text = "Data inserted successfully";
        }
        catch (Exception)
        {
            label1.Text = "Query execution failed";
        }
    }
    catch (Exception)
    {
        label1.Text = "Connection Failed";
    }
}

Until connection open it works fine but after that it is not executing the query and it's not even showing any error.

Aucun commentaire:

Enregistrer un commentaire