更新时间:2022-10-31 12:33:55
在ExecuteReader()之前
试试这个
sqlconnection.Open();
Before ExecuteReader()
try this
sqlconnection.Open();
SqlConnection con =新的SqlConnection("Server =(local)\\ SQLEXPRESS; Initial Catalog = Northwind; Integrated Security = SSPI");
SqlCommand cmd =新的SqlCommand();
cmd.CommandText ="SELECT EmployeeID,FirstName +``''+ LastName作为来自员工的FullName";
cmd.Connection = con;
SqlConnection con = new SqlConnection("Server=(local)\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT EmployeeID, FirstName + '' '' + LastName as FullName FROM Employees";
cmd.Connection = con;
if (con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read()){
}
reader.Close();
con.Close();
或
还请检查下面的链接
http://forums.asp.net/post/4623355.aspx [
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read()) {
}
reader.Close();
con.Close();
or
also check below link
http://forums.asp.net/post/4623355.aspx[^]