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();

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............

Insert into Customer Detail

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

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(); }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.