欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

自己编写sqlhelper类示例分享

程序员文章站 2023-12-19 14:10:10
自己编写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);
            }
        }
    }
}

上一篇:

下一篇: