Hi, I am having difficulties with moving the entire gridview data column into temporary SQL table. I could manage to transfer one value at a time but I wish to transfer in one click.
Here is my C#
protected void TemporarySQLTable(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
using (SqlDataAdapter sda = new SqlDataAdapter())
using (SqlCommand cmd = new SqlCommand("Drop table If exists dbo.#temporary; Select productname into #temporary from DummyTable; Delete from #temporary; INSERT into #temporary (productname) VALUES (@productname); Select productname from #temporary"))
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
cmd.Parameters.AddWithValue("@productname", GridView1.Rows[i].Cells[0].Text);
DataTable dt = new DataTable();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView3.DataSource = dt;
GridView3.DataBind();
}
}
This works great with the rest of the code that can be found here copypaste to TextBox to GV