如何在字段内传递标签值

How can I pass label value inside the field

var conString = ConfigurationManager.ConnectionStrings["CONSTRING"].ConnectionString;
SqlConnection con = new SqlConnection(conString);
string uname = Session["un"].ToString();
Label sid = (Label)DetailsView1.Rows[1].Cells[1].Controls[0].FindControl("lblsid");
TextBox nam = (TextBox)DetailsView1.Rows[2].Cells[1].Controls[0].FindControl("lblname");
TextBox lnam = (TextBox)DetailsView1.Rows[3].Cells[1].Controls[0].FindControl("lbllname");
TextBox cont = (TextBox)DetailsView1.Rows[4].Cells[1].Controls[0].FindControl("lblcon");
TextBox ei = (TextBox)DetailsView1.Rows[5].Cells[1].Controls[0].FindControl("lblei");
TextBox add = (TextBox)DetailsView1.Rows[6].Cells[1].Controls[0].FindControl("lbladd");
TextBox cit = (TextBox)DetailsView1.Rows[7].Cells[1].Controls[0].FindControl("lblcit");
DropDownList typ = (DropDownList)DetailsView1.Rows[8].Cells[1].Controls[0].FindControl("lbltyp");
cmd.Connection = con;
cmd.CommandText = "update seller set  fname ='" + nam.Text + "',  lname ='" + lnam.Text + "', contact ='" + cont.Text + "', address ='" + add.Text + "', city ='" + cit.Text + "', type='" + typ.SelectedValue + "' where sid=" + sid.Text + "";
cmd.Connection.Open();

cmd.ExecuteNonQuery();

DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
BindData();

我知道这种方式是找到控件,但我不知道如何在查询中传递Sid值。有人可以帮忙吗?正在使用 C#

使用参数。下面我将向您展示如何使用名字。你可以像这样完成剩下的事情。

SqlCommand cmd = new SqlCommand(
    "update seller set  fname = @firstName", con);

// 2. define parameters used in command object
SqlParameter param = new SqlParameter();
param.ParameterName = "@firstName";
param.Value = nam;

// 3. add new parameter to command object
cmd.Parameters.Add(param);