Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Button2_Click(object sender, EventArgs e)
   {
       foreach (GridViewRow g1 in GridView1.Rows)
       {

               string Name = g1.Cells[0].Text;
               string job = g1.Cells[1].Text;
               SqlCommand com = new SqlCommand("insert into emp(Name,job) values ('" +Name + "','" +job+ "')", con);
               con.Open();
               com.ExecuteNonQuery();
               con.Close();

       }
   }


sir when i save the value in database i get null value in database i count insert value in database
Posted
Updated 12-Sep-14 20:38pm
v2
Comments
George Jonsson 13-Sep-14 4:27am    
What is the structure of the datatable in the database?

1 solution

Here I'm attaching the code which much similar with your code,but main things is that it works in my application.

C#
protected void Button2_Click(object sender, EventArgs e)
{
        con.Open();
        foreach(System.Data.DataRow D in dt.Rows)
        {
            DropDownList1.Items.Add(D[0].ToString());
        }
        foreach (GridViewRow G in GridView1.Rows)
        {
           string cmdstring = "INSERT INTO TempTable(ID,City) VALUES(" + G.Cells[0].Text + ",'" + G.Cells[1].Text + "')";
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(cmdstring, con);
            cmd.ExecuteNonQuery();
        }
        con.Close();
}


check it if you still not found your output then tell me again.
 
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