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