string DropDownListState="";
string sidtostring = "";
DataListItem dli = (sender as Button).NamingContainer as DataListItem;
DropDownList DropDownListvalue = (sender as Button).NamingContainer as DropDownList; if (dli != null)
{
Label lab = dli.FindControl("Label1") as Label; if (lab != null)
{
sidtostring = lab.Text;
}
} if (DropDownListvalue != null)
{
DropDownList DropDownListdo = DropDownListvalue.FindControl("DropDownList1") as DropDownList; if (DropDownListdo != null)
{
DropDownListState = DropDownListdo.SelectedValue.ToString();
}
}
try
{
string strConn = "server=(local);uid=sa;pwd=123456;database=test_user";
SqlConnection conn = new SqlConnection(strConn); conn.Open();
string strSql = "update OrderSend set send_='"+DropDownListState+"' where id='"+sidtostring+"'";
SqlCommand myCommand = new SqlCommand(strSql, conn);
myCommand.ExecuteNonQuery(); }
catch (Exception ex)
{
Label2.Text = ex.ToString();
}
System.Data.SqlClient.SqlException: 在将 varchar 值 'Label' 转换成数据类型 int 时失败。
怎么将Label转换成int值啊?
请高手指点一下, 我觉得好像是这句有问题 DataListItem dli = (sender as Button).NamingContainer as DataListItem;但是又不知道怎么改..怎么将转成int啊?
id:int 型
sidtostring 的值是STRING ,不能转换成INT
数据库中id int型
lab.Text;
这个的值是多少你要符合整型才能转换的
string 型不能转换int的
<asp:Label id="Label1" Text='<%#Eval("ID")%>' />