Hi how can I pass the connection string from my Main Form to Another form without retyping again those strings. Let say I have separate form for Adding data to database.
Here is my connection codes.
Ho can I make that call from my other form which is Adding records to db?Code:public partial class frmMain : Form { public frmMain() { InitializeComponent(); } SqlConnection con; DataSet ds1; SqlDataAdapter da; private void frmMain_Load(object sender, EventArgs e) { } private void loadRecords_Click(object sender, EventArgs e) { con = new SqlConnection(); con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\MyMDB Records\\myMDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; ds1 = new DataSet(); con.Open(); string sql = "SELECT * FROM tblClients"; da = new SqlDataAdapter(sql, con); da.Fill(ds1, "Clients"); loadLitview(); con.Close(); con.Dispose(); } private void button1_Click(object sender, EventArgs e) { frmAdd FormAdd = new frmAdd(); FormAdd.Show(); }




Reply With Quote