0
    Sqlconnection conn;
    Sqlcommand cmd;

    conn = new SqlConnection("Server=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.MDF;Trusted_Connection=True;User Instance=yes");
    conn.Open();
    string cmdString = "Insert into Customer Detail (Customer_id,Name,Address,Contact_Person,Contact_Person_no)Values ('" + TextBox6.Text + "','" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox5.Text + "','" + TextBox4.Text + "')";
    cmd = new SqlCommand(cmdString, conn);
    cmd.ExecuteNonQuery();
    Label2.Visible = true;
    Label2.Text = "Successfully Submitted";
    TextBox6.Text = "";
    TextBox1.Text = "";
    TextBox2.Text = "";
    TextBox5.Text = "";
    TextBox4.Text = "";
    conn.Close();
3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by sania khan
0

Many times i have tried this code but their always exception occour n page doesn't display..............if any body knows reply quickly because its urgent............

0

Insert into Customer Detail

Does it really have a space? You forgot to ask your question.

Edited by pritaeas

0

try this code :

string sqlIns = "INSERT INTO Customer Detail (Customer_id,Name,Address,Contact_Person,Contact_Person_no) VALUES (@Customer_id,@Name,@Address,@Contact_Person,@Contact_Person_no)            SqlConnection con = new SqlConnection("Server=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.MDF;Trusted_Connection=True;User Instance=yes");

                        SqlCommand cmd = new SqlCommand(sqlIns, con);

            try
            {
                con.Open();

                cmd.Parameters.Add("(@Customer_id ", TextBox6.Text);
                cmd.Parameters.Add("@Name", TextBox1.Text);
                cmd.Parameters.Add("@Address ", TextBox2.Text);
                cmd.Parameters.Add("@Contact_Person ", TextBox5.Text);
                cmd.Parameters.Add("@Contact_Person_no ",TextBox4.Text.Text);

                cmd.ExecuteNonQuery();
                lblStatus.Text = "***Record Inserted.***";
                TextBox6.Text = "";
                TextBox1.Text = "";
                TextBox2.Text = "";
                TextBox5.Text = "";
                 TextBox4.Text = 

            }


            catch (Exception err)
            {
                lblStatus.Text = "***Error in inserting  record***";
                lblStatus.Text += err.Message;
            }
            finally { con.Close(); }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.