Skip to content

How to save data from gridview into another sql table?

Pooja kulkarni

Asked Oct 28, 2018, 11:36 PM EDT1 answer
Share
LinkedInX
ID Criticle Specification One Two Three Four Five TMLCalculation
1 Type of cross mamnber and their orientation as per Drg. 1 1 1 1 1 11
2 Frame Diagonal Dimm 0+_2
1 1 1 1 1
3 CD(Betn 2 ft RSB) 1000+2/-1 1 1 1 1 1 1
4 CD(Betn 2 ft RCB) 1000+2/-1 1 1 1 1 1 1
5 Torque 12kgfm 1 1 1 1 1 1
6 Frame Width Frame Width 1 1 1 1 1 1
7 FrameStaoghtness FrameStaoghtness 1 1 1 1 1 1
8 Frt Shock ABS BKTopening Dimn. & Concentricicity 78+_1 1 1 1 1 1 1
9 Total No. of Cobra Bkt. 1 1 1 1 1 1 1
10 Proper Number Punching on RH Side 1 1 1 1 1 1 1
11 Free from Dust, Scoring, Scratches, Damage, Rust
1 1 1 1 1
1
 
 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    above is my grid view and I want to save that in my sql db table
    I m trying this 
    but it is not working
     
    C#
       protected void Save_Click(object sender, EventArgs e)
            {
                string query2 = "INSERT INTO tbl_Pre_Y1_Bus_Master1_temp  (critical,specification,one,two,three,four,five,TMLCALCULATION) VALUES (@critical,@specification,@one,@two,@three,@four,@five,@TMLCALCULATION)";
                try
                {
                    con = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlserver"].ConnectionString);
                    con.Open();
                    foreach (GridViewRow gvr in GridView2.Rows)
                    {
                        string data1 = gvr.Cells[0].Text;    //get data from BoundField in each row
                        string data2 = ((Label)gvr.FindControl("Label1")).Text;    //get data from control in TemplateField in each row
                        SqlCommand cmd = new SqlCommand(query2, con);                //generate insert sql using above data
                        cmd.ExecuteNonQuery();
                    }
                    con.Close();
                }
                catch (Exception ex)
                {}
    0