资源简介
北大青鸟Accp7.0MyKTV项目完整版 ,中关村校区完整版 带PPT
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace KTV
{
class DBHelper
{
public static string connStr = @“Data Source=SISI;Initial Catalog=KTV;Integrated Security=True“;
static SqlCommand cmd = null;
//获取sqlconnection对象
static SqlConnection Connection{
get {
return new SqlConnection(connStr);
}
}
///
/// 执行增删改返回受影响行
///
///
public static int NoQuery(string sql) {
SqlConnection conn = Connection;
try
{
conn.Open();
cmd= new SqlCommand(sql conn);
return cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
return 0;
}
finally {
conn.Close();
}
}
///
/// 获取SqlDataReader对象
///
///
public static SqlDataReader Reader(string sql) {
SqlConnection conn = Connection;
try
{
conn.Open();
cmd= new SqlCommand(sql conn);
return cmd.ExecuteReader();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
return null;
}
finally {
conn.Close();
}
}
///
/// 获取DataTable对象
///
///
///
public static DataTable Ada(string sql)
{
SqlConnection conn = Connection;
SqlDataAdapter ada = new SqlDataAdapter(sql conn);
DataTable table = new DataTable();
try
{
ada.Fill(table);
return table;
}
catch (Exception ex) {
System.Windows.Forms.MessageBox.Show(ex.Message);
return null;
}
}
///
/// 获取查询单行单列的结果
///
///
///
public static object Scalar(string sql) {
SqlConnection conn = Connection;
try
{
conn.Open();
cmd = new SqlCommand(sql conn);
return cmd.ExecuteScalar();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
return null;
}
f
评论
共有 条评论