如何正确使用OleDbCommand
插入两个不同的表格?这是我到目前为止所尝试的:
GradeConn.Open();
oledDbCmd.Connection = GradeConn;
oledDbCmd.CommandText = "insert into StudentInfo (IdNumber, LastName,FirstName,MiddleName,YearSection,MidtermGrade) values ('" +
txbIdNumber.Text + "','" +
txbLastName.Text + "','" +
txbFirstName.Text + "','" +
txbMiddleName.Text + "','" +
txbYearSection.Text + "','" +
dmg + "')"; "insert into MidTerm (IdNumber,StudentName, QuizzesSeatworks,ClassParticipation,Attendance,Assignments, LaboratoryExercises, CaseStudy,Behavior,ClassStanding,MidtermExam,MidtermGrade ) values('" +
txbIdNumber.Text + "', '" +
txbStudentName.Text + "','" +
mquiz + "','" +
mcp + "','" +
matt + "','" +
mass + "','" +
mlab + "','" +
mcstu + "','" +
mbeh + "','" +
mstanding + "','" +
mte + "','" +
dmg + "')";
int temp = oledDbCmd.ExecuteNonQuery();
if (temp > 0)
{
txbIdNumber.Text = null;
txbLastName = null;
txbFirstName.Text = null;
txbMiddleName.Text = null;
txbYearSection.Text = null;
txbStudentName.Text = null;
MessageBox.Show("Records Successfully Added");
}
else
{
MessageBox.Show("Records Fail to Added");
}
答案 0 :(得分:1)
更改为此并尝试。你错过了; (查询中的分号)
oledDbCmd.CommandText = "insert into StudentInfo (IdNumber, LastName,FirstName,MiddleName,YearSection,MidtermGrade) values ('" +
txbIdNumber.Text + "','" +
txbLastName.Text + "','" +
txbFirstName.Text + "','" +
txbMiddleName.Text + "','" +
txbYearSection.Text + "','" +
dmg + "'); INSERT into MidTerm (IdNumber,StudentName, QuizzesSeatworks,ClassParticipation,Attendance,Assignments, LaboratoryExercises, CaseStudy,Behavior,ClassStanding,MidtermExam,MidtermGrade ) values('" +
txbIdNumber.Text + "', '" +
txbStudentName.Text + "','" +
mquiz + "','" +
mcp + "','" +
matt + "','" +
mass + "','" +
mlab + "','" +
mcstu + "','" +
mbeh + "','" +
mstanding + "','" +
mte + "','" +
dmg + "')";