0
我基本上从microsoft.com复制了该示例,但似乎CommandType
在当前上下文中不存在。该示例不显示声明它。C#执行SqlDataReader缺少变量?
由于
string SQLstring = @"Server=DELLXPS\SQLEXPRESS;Database=SEIN;Integrated Security=true";
SqlConnection sqlConnection1 = new SqlConnection(SQLstring);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "SELECT * FROM ResidentUsers";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
reader = cmd.ExecuteReader();
// Data is accessible through the DataReader object here.
sqlConnection1.Close();
你需要为它的命名空间'using'指令。 – SLaks
感谢芽。加工 – birddseedd