数据库读写操作

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; }

posted @ 2018-08-24 09:45  菜鸟的蜕变  阅读(838)  评论(0编辑  收藏  举报