zoukankan      html  css  js  c++  java
  • 操作数据库的几种写法:

    (1)   string sqlconnection = ConfigurationManager.AppSettings["CeShiConn2"];
                SqlConnection mysqlconnection = new SqlConnection(sqlconnection);
                string sql = "Select * from News ";
                mysqlconnection.Open();
                SqlCommand mycommand = new SqlCommand();
                mycommand.Connection = mysqlconnection;
                mycommand.CommandText = sql;
                SqlDataAdapter myadapter = new SqlDataAdapter();
                myadapter.SelectCommand = mycommand;
                DataSet ds = new DataSet();
                myadapter.Fill(ds, "NewsTable1");
                this.GridView1.DataSource = ds.Tables["NewsTable1"];
                this.GridView1.DataBind();

    (2)

     //try
                //{
                //    using (SqlConnection mysqlconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["CeShiConn"].ToString()))   //引用using好处只需将链接打开不用写关闭链接的代码就会释放资源
                //    {
                //        mysqlconnection.Open();
                //        string sql = "select * from News";
                //        SqlDataAdapter adapter = new SqlDataAdapter(sql, mysqlconnection);
                //        DataSet ds = new DataSet();
                //        adapter.Fill(ds, "NewsTable");
                //        this.GridView1.DataSource = ds.Tables["NewsTable"];
                //        this.DataBind();
                //        if (ds.Tables[0].Rows.Count > 0)
                //        {
                //            Response.Write("<script> window.alert('登陆成功!')</script>");
                //        }
                   
                //    }
                //    this.Label1.Text = "数据库连接完毕";
                //}
                //catch
                //{

                //    Response.Write("<script> window.alert('登录失败,请重新登录!')</script>");
                //}

    (3)   ////int s = Convert.ToInt32(cmd.ExecuteScalar());

  • 相关阅读:
    angular中集中页面传参(我只是知识的搬运工)
    使用Cookie传递参数 ,a页面保存Cookie,b页面读取,代码如下:
    获取并处理地址栏中参数方法
    常见的css命名规范/ID命名规范/常用功能模块的命名
    angularjs 1.x 项目完整的较完整的登录验证具体代码(仅供参考)
    用angular自带的方法获取input中内容(以用户名和密码为例)的字符串长度方法
    jquery 层弹窗传值
    伯乐在线node高手的基础经验 您值得一读
    javascript 代码规范
    正确看待技术
  • 原文地址:https://www.cnblogs.com/lykbk/p/2342342abcd.html
Copyright © 2011-2022 走看看