如何使用select命令将单元格的值从网格视图存储到数据库?

时间:2019-02-24 06:29:05

标签: c# asp.net gridview

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {

                GridViewRow gv = GridView1.SelectedRow;
                Session["m_email"] = gv.Cells[3];
                string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                SqlConnection con = new SqlConnection(constr);
                con.Open();
                string insert = "insert into Service_Info values(@c_email,@email,@first_name,@last_name,@contact,@licenseno,@street,@landmark,@pincode)";
                SqlCommand cmd = new SqlCommand(insert, con);

                cmd.Parameters.AddWithValue("@c_email", Session["user"].ToString());
                cmd.Parameters.AddWithValue("@email",Session["m-email"].ToString());
                cmd.Parameters.AddWithValue("@first_name", Session["user"].ToString());
                cmd.Parameters.AddWithValue("@last_name", Session["user"].ToString());
                cmd.Parameters.AddWithValue("@contact", Session["user"].ToString());
                cmd.Parameters.AddWithValue("@licenseno", Session["user"].ToString());
                cmd.Parameters.AddWithValue("@street", StreetText.Text);
                cmd.Parameters.AddWithValue("@landmark", LandmarkText.Text);
                cmd.Parameters.AddWithValue("@pincode", PincodeText.Text);
                cmd.ExecuteNonQuery();
                Label6.Visible = true;
                Label6.Text = "Successfull...";
                con.Close();
            }
        }

I got this error when i used the code

我想将一个单元格的值从网格视图存储到数据库中。我只想只存储电子邮件单元格值,而不是全部从网格视图中存储。但是我没有办法做到这一点。

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

product()