<connectionstrings> <add name="ConnectionStringdb" connectionstring="Data Source=local; Initial Catalog=TeltonikaCRM; Persist Security Info=True; User ID=sa;password=Ali998877;"> providerName="System.Data.SqlClient" /> <add name="TeltonikaCRMConnectionString" connectionstring="Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Administrator\Documents\TeltonikaCRM.mdf;Integrated Security=True;Connect Timeout=30"> providerName="System.Data.SqlClient" /> </add></add></connectionstrings>
using System.Data.OleDb; using System.ComponentModel; using System.Drawing; using System.Text; namespace CRMTracking.Pages { public partial class Default2 : System.Web.UI.Page { CRMTracking.Classes.DBConnect DBC; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //Establishing the MySQL Connection DBC = new Classes.DBConnect(this.Page); DBC.SetSqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringdb"].ToString()); DataTable dt = new DataTable(); string query; SqlCommand SqlCommand; SqlDataReader reader; SqlDataAdapter adapter = new SqlDataAdapter(); //Open the connection to db //Generating the query to fetch the contact details query = "SELECT * FROM UserInfo"; SqlCommand = new SqlCommand(query, DBC.GetSqlConnection()); //execute the query reader = SqlCommand.ExecuteReader(); txtFName.Text = reader["UFName"].ToString(); //Assign the results GridView1.DataSource = reader; //Bind the data GridView1.DataBind(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.SqlClient; using System.Configuration; using System.Web.UI; namespace CRMTracking.Classes { public class DBConnect { Page Pg=new Page(); SqlConnection SqlConn; public DBConnect(Page CurerntPg) {Pg = CurerntPg;} public void MsgBox(String Message) { Pg.ClientScript.RegisterStartupScript(Pg.GetType(), "MessageBox", "<script language='javascript'>alert('" + Message + "');</script>"); } public SqlConnection GetSqlConnection() {return SqlConn;} public void SetSqlConnection(String CString) { try { SqlConn = new SqlConnection(CString); SqlConn.Open(); } catch (Exception ce) { MsgBox("Error Opening Connection to Sql Server....." + ce); return; } // } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)