public class DataContext { SqlConnection con = new SqlConnection(); SqlCommand cmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); //SqlDataReader dr = new SqlDataReader(); public void Openconnection() { if (con.State == ConnectionState.Closed) { try { string constring = "data source = myserveraddress;Initial Catalog=mywebsite;Persist Security Info=True;User ID=myid;Password=mypassword"; con.ConnectionString = constring; con.Open(); cmd.Connection = con; } catch (Exception ex) { ex.Message.ToString(); } } } public void CloseConnection() { if (con.State == ConnectionState.Open) { con.Close(); } } public DataTable getDataTable(string Query) { DataTable dt = new DataTable(); Openconnection(); cmd.CommandType = CommandType.Text; cmd.CommandText = Query; da.SelectCommand = cmd; da.Fill(dt); CloseConnection(); return dt; } public int executeNonquery(string Query) { Openconnection(); cmd.CommandType = CommandType.Text; cmd.CommandText = Query; int i = cmd.ExecuteNonQuery(); CloseConnection(); return i; }
Data Source=...
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)