I am pretty new to C#. I am trying to create a WinForms app where you can enter personal info and it gets stored in a SQL table. The code runs without a hitch, but afterwards the new entry is nowhere to be found. I created the database in Visual Studio.
I ran the debugger and found another .mdf file in the debug folder. When I copied it and opened it in SSMS I find my new entry, but not in the original DB. How do get the entries to be stored in the proper db file?
public partial class Form3 : Form
{
SqlConnection cnConnection = new SqlConnection(Properties.Settings.Default.VotingDbConnectionString);
private SqlCommand cmd;
private void Button1_Click(object sender, EventArgs e)
{
if (checkBox.Checked)
{
var pId = pIdTextBox.Text;
var fName = fNameTextBox.Text;
var lName = lNameTextBox.Text;
var dob = dobTexbox.Text;
var gender = genderTexbox.Text;
cnConnection.Open();
cmd = new SqlCommand("INSERT INTO tbl_People(pId, fName, lName, dob, gender) VALUES('"+pId+"', '"+fName+ "', '"+lName+ "', '"+dob+"', '"+gender+"')", cnConnection);
cmd.ExecuteNonQuery();
MessageBox.Show("Data has been saved.");
cnConnection.Close();
}