Quantcast
Channel: DataSource Controls - SqlDataSource, ObjectDataSource, etc.
Viewing all articles
Browse latest Browse all 956

Get Column name for an Insert Query from The Selected GridView Row

$
0
0

Hi Guys, I am trying to insert data in an SQL table by executing an Insert Query. 

The problem is that I need to get the column name from a cell in the selected gridview Row.

Here's the snippet:

SqlCommand cmd30 = new SqlCommand("insert into mytable ( '"+GridView7.SelectedRow.Cells[0].Text+"' , r_id) values ('"+ GridView7.SelectedRow.Cells[1].Text +"', '"+TextBox1.Text+"')",con30);
        cmd30.ExecuteNonQuery();

**r_id is not a Primary Key.

The Error is get is:

Incorrect syntax near 'r_id'.

Also is it possible to get the column name of the table from a specific cell of the selected Gridview row?

That seems to be the problem.

Any Help will be appreciated.

Thanks,

Shaleen


Viewing all articles
Browse latest Browse all 956

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>