自己编写sqlhelper类示例分享
程序员文章站
2024-02-23 12:42:16
自己编写sqlhelper,大家参考使用吧复制代码 代码如下:using system;using system.collections.generic;using sys...
自己编写sqlhelper,大家参考使用吧
using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.windows;
using system.windows.controls;
using system.windows.data;
using system.windows.documents;
using system.windows.input;
using system.windows.media;
using system.windows.media.imaging;
using system.windows.navigation;
using system.windows.shapes;
using system.data; using system.data.sqlclient;
namespace sqlhelper
{
/// <summary>
/// window1.xaml 的交互逻辑
/// </summary>
public partial class window1 : window
{
public window1()
{
initializecomponent();
}
//只用来执行查询结果比较少的sql
private void btnds_click(object sender, routedeventargs e)
{
sqlhelper.executenonqurey("insert into t_student(name,age) values('张三',55)",
new sqlparameter[0]);
messagebox.show("添加成功");
}
private void btndataset_click(object sender, routedeventargs e)
{
dataset ds= sqlhelper.executedataset("select * from t_student where hobbit='@hobbit'",
new sqlparameter[]{new sqlparameter("'@hobbit'","哈哈哈")});
foreach(datarow row in ds.tables[0].rows)
{
string name = (string)row["name"];
messagebox.show(name);
}
}
}
}
复制代码 代码如下:
using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.windows;
using system.windows.controls;
using system.windows.data;
using system.windows.documents;
using system.windows.input;
using system.windows.media;
using system.windows.media.imaging;
using system.windows.navigation;
using system.windows.shapes;
using system.data; using system.data.sqlclient;
namespace sqlhelper
{
/// <summary>
/// window1.xaml 的交互逻辑
/// </summary>
public partial class window1 : window
{
public window1()
{
initializecomponent();
}
//只用来执行查询结果比较少的sql
private void btnds_click(object sender, routedeventargs e)
{
sqlhelper.executenonqurey("insert into t_student(name,age) values('张三',55)",
new sqlparameter[0]);
messagebox.show("添加成功");
}
private void btndataset_click(object sender, routedeventargs e)
{
dataset ds= sqlhelper.executedataset("select * from t_student where hobbit='@hobbit'",
new sqlparameter[]{new sqlparameter("'@hobbit'","哈哈哈")});
foreach(datarow row in ds.tables[0].rows)
{
string name = (string)row["name"];
messagebox.show(name);
}
}
}
}