向各位请教一个asp.net中数据类型转换的问题!
我写了一个asp.net程序,如下:
SqlConnection objConnection;
SqlCommand objCommand;
objConnection=new SqlConnection("server=bob;trusted_connection=true;database=Northwind;uid=sa;pwd=;integrated security=true;");
objCommand=new SqlCommand("select FirstName,LastName,Country,Region,City,Notes from Employees where EmployeeID='radEmployees.SelectedItem.Value'",objConnection);
objConnection.Open();
dgEmployee.DataSource=objCommand.ExecuteReader();
dgEmployee.DataBind();
objConnection.Close();
其中radEmployees是一个RadioButtonlist控件,dgEmployee是一个DataGrid.
编译时产生如下异常:
将 varchar 值 'radEmployees.SelectedItem.Value' 转换为数据类型为 int 的列时发生语法错误。
Exception Details: System.Data.SqlClient.SqlException: 将 varchar 值 'radEmployees.SelectedItem.Value' 转换为数据类型为 int 的列时发生语法错误。
Source Error:
Line 39:
Line 40: dgEmployee.DataSource=objCommand.ExecuteReader();
Line 41: dgEmployee.DataBind();异常点
Line 42: objConnection.Close();
Line 43:
请教各位大虾,这样的数据转换问题应该如何解决。请各位帮帮忙,急等中!!!