码迷,mamicode.com
首页 > Web开发 > 详细

ado.net入门

时间:2018-08-03 01:07:29      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:set   ring   cal   cut   init   sharp   data   comm   入门   

            //1.0连接字符串
            string conStr = "Data Source=.;Initial Catalog=test;User ID=sa;Password=‘qwertyu‘";
            //2.0返回第行第一列结果
            using (SqlConnection conn = new SqlConnection(conStr))
            {
                string sqlStr = @"select count(1) from sys_users where deleteflag =0";
                conn.Open();
                SqlCommand command = new SqlCommand(sqlStr, conn);
                int result = Convert.ToInt32(command.ExecuteScalar());
            }

            //3.0返回第行第一列结果
            using (SqlConnection conn = new SqlConnection(conStr))
            {
                string sqlStr = @"insert into sys_users (ID,Name,Age) values(100,‘12334efdgdfg‘,13)";
                //string sqlStr = @"insert into sys_users values(100,‘12334efdgdfg‘,13,0)";
                //update Sys_Users set Name=‘pppppppppp‘ where ID=1
                conn.Open();
                SqlCommand command = new SqlCommand(sqlStr, conn);
                int result = Convert.ToInt32(command.ExecuteNonQuery());
            }


            //4.0返回结果集
            SqlDataAdapter da = new SqlDataAdapter("select name from Sys_Users  where DeleteFlag=0;select age from Sys_Users  where DeleteFlag=0", conStr);
            DataSet ds = new DataSet();
            da.Fill(ds);

  

ado.net入门

标签:set   ring   cal   cut   init   sharp   data   comm   入门   

原文地址:https://www.cnblogs.com/junhuang/p/9410780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!