自己编写sqlhelper类示例分享
更新时间:2020年6月25日 11:36 点击:2063
自己编写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);
}
}
}
}
相关文章
- 这篇文章主要为大家详细介绍了C#实现较为实用SQLhelper的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-25
- 这篇文章主要和大家一起学习C# SqlHelper应用开发,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-25
- 这篇文章主要介绍了自己编写sqlhlper类示例,需要的朋友可以参考下...2020-06-25
- 本篇文章主要介绍了使用C#编写SqlHelper类,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
- 数据连接池c# SQLHelper 实现代码...2020-06-25
c#中SqlHelper封装SqlDataReader的方法
这篇文章主要介绍了c#中SqlHelper封装SqlDataReader的方法,涉及C#针对数据库相关操作封装与使用的技巧,需要的朋友可以参考下...2020-06-25- 这篇文章主要介绍了四个常用的.NET的SQLHELPER方法,在WinForm的实际开发中比较常用,需要的朋友可以参考下...2021-09-22
- 这篇文章主要介绍了php中分页及SqlHelper类用法,结合实例形式分析了php数据库查询类与分页类的定义与具体使用技巧,需要的朋友可以参考下...2017-01-15
微软官方SqlHelper类 数据库辅助操作类 <font color=red>原创</font>
本文主要介绍微软官方的数据库操作类极其使用方法,帮助大家利用已经非常成熟的类库来进行快速开发。...2021-09-22