zoukankan      html  css  js  c++  java
  • asp.net 数据操作三步曲(一) :)

    一: 在类中 建立数据库连接

    最好使 namespace
    using System.Data.SqlClient;
    /// <summary>
    /// Summary description for db
    /// </summary>
    ///
    namespace vote
    {
        public class db
       
        {    
            public static SqlConnection createconnection ()
            {
                SqlConnection con = new SqlConnection("server=GYYKF;database=vote;uid=sa;pwd=sa;");
                return con;
            }
        }
    }

    二: 绑定数据库

         首先打开数据库:
            SqlConnection con = Class1.createconnection();
            con.Open();
          然后使用命令提取数据:
    如:
          SqlCommand itemcmd = new SqlCommand("select votedetailsid,voteitem from votedetails where voteid=" + this.voteid, con);
            SqlDataReader sdr = itemcmd.ExecuteReader();
            this.rbtn.DataSource = sdr;//设置数据源
            this.rbtn.DataTextField = "voteitem";
            this.rbtn.DataValueField = "votedetailsid"; //绑定属性
            this.rbtn.DataBind();  //把数据绑定到控件上
            sdr.Close();          
            con.Close();  //关闭连接


    三:更新数据库
      首先打开数据库:
     SqlConnection con = Class1.createconnection();
            con.Open();
    然后使用命令:
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "update votedetails set votenum=votenum+1 where id=1;
            cmd.ExecuteNonQuery();//更新
            con.Close();


    第一次写就写这么多了,明天继续。。。。。。

  • 相关阅读:
    pands数据框(DataFrame)02
    mysql 临时表
    【转】Mysql 多表连接查询的执行细节 (一)
    【转】cuckoo hash
    [转]全域哈希
    【转】 bloom filter
    【转】bitmap
    golang 反汇编代码阅读-- defer
    assignment3
    Lecture 12: Visualizing and Understanding
  • 原文地址:https://www.cnblogs.com/gergro/p/352885.html
Copyright © 2011-2022 走看看