編寫sqlhelper類別範例

高洛峰
發布: 2023-03-04 19:56:02
原創
1282 人瀏覽過

自己寫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(&#39;张三&#39;,55)",
                new SqlParameter[0]);
            MessageBox.Show("添加成功");
        }

        private void btnDataSet_Click(object sender, RoutedEventArgs e)
        {
            DataSet ds= SqlHelper.ExecuteDataSet("select * from T_Student where hobbit=&#39;@hobbit&#39;",
                new SqlParameter[]{new SqlParameter("&#39;@hobbit&#39;","哈哈哈")});
            foreach(DataRow row in ds.Tables[0].Rows)
            {
                string name = (string)row["Name"];
                MessageBox.Show(name);
            }
        }
    }
}
登入後複製

更多寫sqlhelper類範例相關文章請關注PHP中文網!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!