自己編寫sqlhelper類示例分享
更新時間:2014年04月02日 10:09:30 作者:
這篇文章主要介紹了自己編寫sqlhlper類示例,需要的朋友可以參考下
自己編寫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();
}
//只用來執(zhí)行查詢結(jié)果比較少的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);
}
}
}
}
復(fù)制代碼 代碼如下:
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();
}
//只用來執(zhí)行查詢結(jié)果比較少的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);
}
}
}
}
您可能感興趣的文章:
- php中分頁及SqlHelper類用法實例
- C#實現(xiàn)較為實用的SQLhelper
- 微軟官方SqlHelper類 數(shù)據(jù)庫輔助操作類
- C#基于SQLiteHelper類似SqlHelper類實現(xiàn)存取Sqlite數(shù)據(jù)庫的方法
- c#中SqlHelper封裝SqlDataReader的方法
- C#實現(xiàn)操作MySql數(shù)據(jù)層類MysqlHelper實例
- 四個常用的.NET的SQLHELPER方法實例
- c# SQLHelper(for winForm)實現(xiàn)代碼
- asp.net SqlHelper數(shù)據(jù)訪問層的使用
- C# SqlHelper應(yīng)用開發(fā)學(xué)習(xí)
相關(guān)文章
winform模擬鼠標(biāo)按鍵的具體實現(xiàn)
這篇文章介紹了winform模擬鼠標(biāo)按鍵的具體實現(xiàn),有需要的朋友可以參考一下2013-10-10C#調(diào)用百度翻譯API實現(xiàn)一個翻譯功能
一直喜歡用Google Translate API進(jìn)行在線翻譯,但是服務(wù)越來越慢這篇文章,所以只能換一個了,主要給大家介紹了關(guān)于C#調(diào)用百度翻譯API實現(xiàn)一個翻譯功能的相關(guān)資料,需要的朋友可以參考下2021-06-06