c#基础链接数据库查询表

直接上代码
public class WeChatDao
{
//声明字符串
string connectionString = @“server=. ;uid=sa;pwd=****;database=Service1”;
public void ToPublic()
{
//声明集合对象
List<WX_SUser> wx = new List<WX_SUser>();
//声明链接
SqlConnection con = new SqlConnection(connectionString);
//操作SQL
string sql = “select * from WX_SUser”;
//声明适配器对象
SqlDataAdapter da = new SqlDataAdapter(sql, con);
//声明DataTable
DataTable trable = new DataTable();
//填充数据
da.Fill(trable);
//遍历到集合中
WX_SUser w = new WX_SUser();
foreach (DataRow row in trable.Rows)
{
w.CustomerId = Convert.ToInt32(row[“CustomerId”]);
w.Sex = Convert.ToInt32(row[“Sex”]);
w.IsEnabled = Convert.ToInt32(row[“IsEnabled”]);
w.CreatedTime = Convert.ToDateTime(row[“CreatedTime”]);
w.ModifiedTime = Convert.ToDateTime(row[“ModifiedTime”]);
w.IsDeleted = Convert.ToInt32(row[“IsDeleted”]);
wx.Add(w);
}

    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值