I have form and dataGridView connected to table in the database,
when I add records It shows up in the dataGridView, but when I stop running the table returns empty!
here is the code:
string employeeName = "person";
string employeeUserName ="person1";
string emplpyeeNotes = "empty";
string employeePassword = "123";
int employeeSalary = 4000;
try
{
SqlConnection cn = new SqlConnection(Properties.Settings.Default.StudentManagementDBConnectionString);
cn.Open();
string sql = "INSERT INTO Employee (Name,Salary,UserName,Password,Notes) VALUES(@name, @salary, @userName, @password, @notes)";
SqlCommand exsql = new SqlCommand(sql, cn);
exsql.Parameters.AddWithValue("@name", employeeName);
exsql.Parameters.AddWithValue("@salary", employeeSalary);
exsql.Parameters.AddWithValue("@userName", employeeUserName);
exsql.Parameters.AddWithValue("@password", employeePassword);
exsql.Parameters.AddWithValue("@notes", emplpyeeNotes);
exsql.ExecuteNonQuery();
MessageBox.Show("employee added Successfully", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.employeeTableAdapter.Fill(this.studentManagementDBDataSet.Employee);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…