“/WebSite”应用程序中的服务器错误 Fill: SelectCommand.Connection 属性尚未初始化,
昨天我在DataList控件中显示userName,出现错误;
求高手解决!
抱错信息:在调用“Fill”前,SelectCommand 属性尚未初始化。
“/WebSite10”应用程序中的服务器错误。
在调用“Fill”前,SelectCommand 属性尚未初始化。
异常详细信息: System.InvalidOperationException: 在调用“Fill”前,SelectCommand 属性尚未初始化。
use_data.cs如下:
private DataSet FillRetrieveData(String commandText, String paramName, String paramValue)
{
DataSet data = new DataSet();
SqlConnection conn = null;
conn = Conn.GetConnection();
SqlCommand command = new SqlCommand(commandText,conn);
command.CommandText = commandText;
command.CommandType = CommandType.StoredProcedure;
if(paramName!="")
{
SqlParameter param = new SqlParameter(paramName, SqlDbType.NVarChar, 255);
param.Value = paramValue;
command.Parameters.Add(param);
}
SqlDataAdapter sad= new SqlDataAdapter(command);
sad.Fill(data); (错误源,未初始化)
Conn.Disconnect();
sad.Dispose();
command.Dispose();
return data;
}