C# .NET - Retrieving datas from Database - Asked By chitra ganapathy on 25-Sep-12 06:20 AM

hi,
 i have created database by adding add->new item->service database,
and i used the following code to save the data

private



void btn_save_Click(object sender, EventArgs e)


{



try


{



string c = Application.StartupPath;




SqlConnection con = new SqlConnection(@"AttachDbFilename=G:\egprogram_with_db\egprogram_with_db\bin\Debug\Database1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");


con.Open();



SqlCommand cmd = new SqlCommand("Insert into Codedetails values('TF','" + txt_productcode.Text + "','" + txt_productname.Text + "','" + txt_brandcode.Text + "','" + txt_brandname.Text + "')", con);


cmd.ExecuteNonQuery();

con.Close();

assigngrid_codeentry();

}



catch (Exception ex)


{

}

}
here the datas saved correctly...but in the next time, its doesnt appear.

public



void assigngrid_codeentry()


{



try


{



SqlConnection con = new SqlConnection(@"AttachDbFilename=G:\egprogram_with_db\egprogram_with_db\bin\Debug\Database1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");


con.Open();



SqlDataAdapter da = new SqlDataAdapter("Select * from Codedetails", con);




DataSet ds = new DataSet();


da.Fill(ds);

dataGridView_codeentry.DataSource = ds.Tables[0];

con.Close();

}



catch (Exception ex)


{

}

}


my doubt is datas are saving inside the bin/debug or outside the bin...because i can find two mdf file in the folder.
Plz clear me this doubt

Robbe Morris replied to chitra ganapathy on 25-Sep-12 09:25 AM
Do not put your database files in the bin\debug folder.
Jitendra Faye replied to chitra ganapathy on 26-Sep-12 01:50 AM
As you given mdf file location as bin so sure data will be stored in this location only.
chitra ganapathy replied to Robbe Morris on 26-Sep-12 01:58 AM
hi Robbe, thanks for ur reply, by default the database is inside the bebug folder when we add new item and database, so that if we create setup file, the database also attached with the setup file.  I want the clear solution for this. i am in more confusing.