winfrom如何使用数据库,求完整代码

我想在窗体中调用数据库,可我忘记代码了,百度也没找到合适的,所以我想求完整代码。不要求三层架构
如何在winfrom里调用sql server数据库,求完整代码

MySQLConnection conn = null;
conn = new MySQLConnection(new MySQLConnectionString("58.96.191.232", db_name, "test", "1234", 3306).AsString);
conn.Open();
MySQLCommand commn = new MySQLCommand("set names gb2312", conn);
commn.ExecuteNonQuery();
string sql = "select uname as 用户名,FROM_UNIXTIME(sh_user_cash.create_time,'%Y-%m-%d %h:%i:%s') as 申请入金时间,amount as 申请入金金额 from sh_user_cash,sh_user where sh_user_cash.cash_type=0 and sh_user_cash.create_time >= (FLOOR((unix_timestamp(now()))/86400)*86400-28800 )AND sh_user_cash.user_id=sh_user.id;"; //当日入金申请查询语句
MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);
DataSet ds = new DataSet();
mda.Fill(ds, "table1");
this.dataGridView1.DataSource = ds.Tables["table1"];
this.tabPage1.Controls.Add(this.dataGridView1);
conn.Close();

仅供参考

MySQLConnection conn = null;
conn = new MySQLConnection(new MySQLConnectionString("58.96.191.232", db_name, "test", "1234", 3306).AsString);
conn.Open();
MySQLCommand commn = new MySQLCommand("set names gb2312", conn);
commn.ExecuteNonQuery();
string sql = "select uname as 用户名,FROM_UNIXTIME(sh_user_cash.create_time,'%Y-%m-%d %h:%i:%s') as 申请入金时间,amount as 申请入金金额 from sh_user_cash,sh_user where sh_user_cash.cash_type=0 and sh_user_cash.create_time >= (FLOOR((unix_timestamp(now()))/86400)*86400-28800 )AND sh_user_cash.user_id=sh_user.id;"; //当日入金申请查询语句
MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);
DataSet ds = new DataSet();
mda.Fill(ds, "table1");
this.dataGridView1.DataSource = ds.Tables["table1"];
this.tabPage1.Controls.Add(this.dataGridView1);
conn.Close();

仅供参考

using System.Data.SqlClient;
SqlConnection conn = new SqlConnection("Server=.;DataBase=Northwind;Uid=sa;pwd=123;");
//数据库连接驱动,.代表本机,也可以用“(Local)、127.0.0.1,局域网的本地IP都可以”
//DataBase 跟上的是你要连接数据库名称
//Uid ,全称是 User ID , 连接数据库的用户名,,默认是 sa
//Password 简称是 pwd ,是连接数据库的密码,,默认是空的,但是我这边自己有设置密码
//Pwd 为空,可以不写 “Server=.;DataBase=Northwind;Uid=sa;”就可以了
scn.open();//打开连接
SqlCommand scd = new SqlCommand("select * from 存用户名的表 where 用户名=输入的用户名 and 密码=输入的密码",scn);
SqlDataReader sdr = scd.ExecuteReader();//读取数据
if(sdr.reder())
{
通过登录
}
else
{
messagebox.show("出错!");
}