using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
public static class SqlDataAccess
{
public static SqlCommand CreateCommand()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = WebConfig.ConnectionString;
SqlCommand comm = conn.CreateCommand();
comm.CommandType = CommandType.StoredProcedure;
return comm;
}
public static DataTable ExecuteSelectCommand(SqlCommand comm)
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = comm;
DataTable table = new DataTable();
adapter.Fill(table);
return table;
// หรือ ใช้เป็น dataset
DataSet ds new DataSet();
adapter.Fill(ds);
return ds;
}
public static string ExecuteScalar(SqlCommand comm)
{
comm.Connection.Open();
string result = comm.ExecuteScalar().ToString();
comm.Connection.Close();
return result;
}
public static int ExecuteNonQuery(SqlCommand comm)
{
comm.Connection.Open();
int result = comm.ExecuteNonQuery();
comm.Connection.Close();
return result;
}
}
}
public static string ExecuteScalar(SqlCommand comm)
{
comm.Connection.Open();
string result = comm.ExecuteScalar().ToString();
comm.Connection.Close();
return result;
}
public static int ExecuteNonQuery(SqlCommand comm)
{
comm.Connection.Open();
int result = comm.ExecuteNonQuery();
comm.Connection.Close();
return result;
}
}
No comments:
Post a Comment