
放回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();
- }
- }
- }
评价
排名
12
文章
74
粉丝
4
评论
15
ASP.NET中webform中的几个生命周期函数
修心 : 什么周期除了这些还有什么呢
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术