Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Dear Friends,

I have a Database with No.of Tables in it.

I have a one Table in it, which displays records into gridview.

I need to Insert Gridview Row to New Table in SqlServer 2005 database. when Select button Click in Gridview.....SELECT button will be Cell[0].

How to Insert the Selected Row From GRIDVIEW into Sqlserver 2005 Database New Table.


Please help me, Thanks.
Posted

Check out the following code
C#
protected void grdVacancy_SelectedIndexChanged(object sender, EventArgs e)
    {
       string query= "insert into tablename (columnname) values('"+ grdVacancy.SelectedRow.Cells[1].Text+"')";
    }

mark it solution if you got your answer and dont forget to rate..



Thanks
Ashish
 
Share this answer
 
Comments
Member 11226864 20-Nov-14 6:06am    
Not working
C#
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow r = GridView1.SelectedRow;
        string strQuery = "insert into table values('" + r.Cells[0] + "','" + r.Cells[1] + "')";
    }


improved only for making in code
 
Share this answer
 
v2
write your insert query in selectedindexchange event of gridview.
 
Share this answer
 
v2
Comments
Ranjith Reddy CSE 20-Jun-12 4:53am    
Please can you show me, how to write.

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