using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.SqlClient; using System.Data; public class DataAccess { SqlConnection _MyConnection = new SqlConnection(); SqlCommand _MyCommand = new SqlCommand(); SqlDataAdapter _MyAdapter = new SqlDataAdapter(); private bool OpenConnection() { try { _MyConnection.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|ASPNETDB.MDF;Integrated Security=True;User Instance=True"; if (_MyConnection.State == System.Data.ConnectionState.Closed) { _MyConnection.Open(); return true; } return false; } catch { return false; } } private void CloseConnection() { _MyConnection.Close(); } public int ExeIUDQuery(string Query) { OpenConnection(); _MyCommand.Connection = _MyConnection; _MyCommand.CommandText = Query; int RowAffectedCount = _MyCommand.ExecuteNonQuery(); CloseConnection(); return RowAffectedCount; } public DataSet ExeSQuery(string Query) { OpenConnection(); _MyCommand.Connection = _MyConnection; _MyCommand.CommandText = Query; _MyAdapter.SelectCommand = _MyCommand; DataSet __DS = new DataSet(); _MyAdapter.Fill(__DS); CloseConnection(); return __DS; } public DataAccess() { } }
protected void Button1_Click(object sender, EventArgs e) { string user = Txtuser.Text; string pas = Txtpass.Text; string query = ""; query = "INSERT INTO a (name,family) VALUES ( + user + ,+ pas+ ); DataAccess DA = new DataAccess(); DA.ExeIUDQuery(query); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)