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

最好使 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 voteupdate votedetails set votenum=votenum+1 where id=1;
        cmd.ExecuteNonQuery();//更新
        con.Close();


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

相关文章:

  • 2021-06-11
  • 2021-06-01
  • 2021-10-18
  • 2022-02-17
  • 2022-01-01
  • 2022-03-05
  • 2021-08-18
猜你喜欢
  • 2021-09-02
  • 2020-01-14
  • 2022-01-05
  • 2022-12-23
  • 2020-01-16
相关资源
相似解决方案