一: 在类中 建立数据库连接
最好使 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();
第一次写就写这么多了,明天继续。。。。。。
相关文章: