分类:
NET
放回datatable
//1:开打数据库的连接 using (SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=123456;database=test")) { conn.Open(); //2:构建执行sql语句的对象,指定一个sql语句 using (SqlCommand com = new SqlCommand("select * from UserInfo", conn)) { //3:执行sql填充到DataTable SqlDataAdapter adapter = new SqlDataAdapter(com); DataTable table = new DataTable(); adapter.Fill(table); return table; } }
返回sqldatareader
//1:开打数据库的连接 using (SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=123456;database=test")) { conn.Open(); //2:构建执行sql语句的对象,指定一个sql语句 using (SqlCommand com = new SqlCommand("select * from UserInfo", conn)) { //3:执行sql返回SqlDataReader SqlDataReader reader = com.ExecuteReader(); //读取(SqlDataReader一行一行的读取) while (reader.Read()) { string userAcount = reader[1].ToString(); string username = reader["username"].ToString(); string userSex = reader["userSex"].ToString(); } } }
评价
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术