Click here to Skip to main content
15,921,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my insert statement. Records are not inserting but no errors showing also. Please help
C#
protected void btn_Add_Click(object sender, EventArgs e)
    {
      

        if (btn_Add.Text == "Submit")
        {

            string Height = txtHeight.Text;
            string TopDia = Convert.ToString(txtTopDiaMeter.Text);
            string BottomDia = Convert.ToString(txtBottomDiaMeter.Text);
            string ShaftThick = Convert.ToString(txtShaftThick.Text);
            string BlackWt = Convert.ToString(txtBlackWeight.Text);
            string TotManHrPerPole = Convert.ToString(txtTotManHrPoleData.Text);
            string Plate_Length = Convert.ToString(txtPlateLength.Text);
            string PLATE_DIA = Convert.ToString(txtPlateDia.Text);
            string PLATE_THICKNESS = Convert.ToString(txtPlateThick.Text);
            System.Collections.Hashtable ht = (System.Collections.Hashtable)Session["UserDetails"];
            Int64 UsrId = (Int64)ht["UserID"];
            string CreatedBy = Convert.ToString(UsrId);
            string FoundBoltId = Convert.ToString(ddlFoundationBolt.SelectedValue);
            string PoleTypeId = Convert.ToString(ddlPoltype.SelectedValue);
            string ProductTypeID = Convert.ToString(ddlPdtType.SelectedValue);

            string Status = chkActive.Checked ? "True" : "False";
            string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
            fileuploadimages.SaveAs(Server.MapPath("~/Images/Pole Data/" + filename));

            try
            {
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["valmont"].ToString());
                con.Open();
                SqlCommand cmd = new SqlCommand("Insert into DEF_POLE_DATA_MST(Height,TopDia,BottomDia,ShaftThick,BlackWt,TotManHrPerPole,Plate_Length,PLATE_DIA,PLATE_THICKNESS,CreatedBy,FoundBoltId,PoleTypeID,ProductTypeID,Status,ImagePath) values(@Height,@TopDia,@BottomDia,@ShaftThick,@BlackWt,@TotManHrPerPole,@Plate_Length,@PLATE_DIA,@PLATE_THICKNESS,@CreatedBy,@FoundBoltId,@PoleTypeId,@ProductTypeID,@Status,@ImagePath)", con);

                cmd.Parameters.AddWithValue("@Height", Height);
                cmd.Parameters.AddWithValue("@TopDia", TopDia);
                cmd.Parameters.AddWithValue("@BottomDia", BottomDia);
                cmd.Parameters.AddWithValue("@ShaftThick", ShaftThick);
                cmd.Parameters.AddWithValue("@BlackWt", BlackWt);
                cmd.Parameters.AddWithValue("@TotManHrPerPole", TotManHrPerPole);
                cmd.Parameters.AddWithValue("@Plate_Length", Plate_Length);
                cmd.Parameters.AddWithValue("@PLATE_DIA", PLATE_DIA);
                cmd.Parameters.AddWithValue("@PLATE_THICKNESS", PLATE_THICKNESS);
                cmd.Parameters.AddWithValue("@CreatedBy", CreatedBy);
                cmd.Parameters.AddWithValue("@FoundBoltId", FoundBoltId);
                cmd.Parameters.AddWithValue("@PoleTypeId", PoleTypeId);
                cmd.Parameters.AddWithValue("@ProductTypeID", ProductTypeID);
                cmd.Parameters.AddWithValue("@Status", Status);
                cmd.Parameters.AddWithValue("@ImagePath", "~/Images/Pole Data/" + filename);
                cmd.ExecuteNonQuery();
                con.Close();

                BindGrid();
                Accordian.SelectedIndex = 1;
                JQUERYDisplay.ShowAlertMessage("Record Inserted Successfully");

                CleraFields();

            }
            catch (Exception ex)
            {
                JQUERYDisplay.ShowAlertMessage(ex.Message);
            }
            finally
            {
                
            }
        }


You can find the table here

https://picasaweb.google.com/lh/photo/QmT9efouyNXD85fyuF7KaNMTjNZETYmyPJy0liipFm0?feat=directlink[^]
Posted
Comments
Mayank Vashishtha 25-Aug-15 4:10am    
What does ExecuteNonQuery() returns?
Arasappan 25-Aug-15 5:28am    
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["valmont"].ConnectionString);
Advay Pandya 25-Aug-15 5:35am    
Please make sure the database of connection string and database that you are checking are same.
ZurdoDev 25-Aug-15 7:52am    
It's very simple, just debug it.

1. Make sure your code is running, don't just assume that it is. Put a breakpoint and walk through the code.
2. Run a sql trace. Chances are you are pointing to a different db than you think.
jaket-cp 25-Aug-15 9:10am    
Reading the other comments, have you considered using the SQL Server Profile to see if the statements are being executed on the db server in question.
This link may help: https://msdn.microsoft.com/en-us/library/ms181091(v=sql.110).aspx

I notice you are saving a file along with inserting the database record. Is the file also being saved? If not then your condition
C#
if (btn_Add.Text == "Submit")
may never be true.
 
Share this answer
 
SQL
Use break point and check your condition. is it true or false?
i think statement is false.
 
Share this answer
 
REMOVE TRY CATCH AND THEN TRY IT ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900