数据库读写操作

string connStr = string.Format("server={0};User ID={1};Password={2};database={3};Connection Reset=FALSE;Asynchronous Processing=true",".\SQLEXPRESS", "sa","123456" ,"学生信息");
SqlConnection cn = new SqlConnection(connStr);

cn.Open();

string str = "select * from stu_1";
SqlCommand cmd = new SqlCommand(str, cn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(String.Format("{0}, {1}",
reader[0], reader[1]));
}

}

public static string localhost { get; set; }

public static object 学生信息 { get; set; }

原文地址:https://www.cnblogs.com/smghome/p/9528002.html