using System.Data.SqlClient;
using System.Collections.Generic;
private SqlConnection sqlConnection = null;
private DataSet dsData = null;
private static string strDbConnection = "";
public static void Main()
Console.WriteLine("Hello World");
public static SqlConnection GetConnection()
var conStr = "Data Source=(LocalDb)\v11.0;Initial Catalog=MyDB;Integrated Security=True";
var sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = conStr;
public DataTable SearchVendors(string vendorType = "", string vendorName = "", int id = 0, int isActive = -1)
string sProcName = "SearchVendors";
List<SqlParameter> paramList = new List<SqlParameter>();
paramList.Add(new SqlParameter("@ID", id < 1 ? (object)DBNull.Value : id));
paramList.Add(new SqlParameter("@VENDOR_TYPE", String.IsNullOrEmpty(vendorType) ? (object)DBNull.Value : vendorType));
paramList.Add(new SqlParameter("@VENDOR_NAME", String.IsNullOrEmpty(vendorName) ? (object)DBNull.Value : vendorName));
paramList.Add(new SqlParameter("@IS_ACTIVE", isActive < 0 ? (object)DBNull.Value : isActive));
return OpenDataTable(sProcName, paramList.ToArray()).Tables[0];
public void OpenConnection()
sqlConnection = GetConnection();
public void CloseConnection()
if (sqlConnection != null)
public DataSet OpenDataTable(string spName, SqlParameter[] spParams = null)
using (SqlCommand _sqlCommand = new SqlCommand())
_sqlCommand.CommandText = spName;
_sqlCommand.CommandType = CommandType.StoredProcedure;
_sqlCommand.Connection = sqlConnection;
_sqlCommand.CommandTimeout = 60;
_sqlCommand.Parameters.AddRange(spParams);
using (SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(_sqlCommand))
SqlDataAdapter.Fill(dsData);