두 테이블이있는 데이터베이스가 있습니다. StudentID는 'StudentList'테이블의 기본 키이고 StudentID는 'JournalEntries'테이블의 외래 키입니다.데이터베이스 쿼리 문자열에 액세스
내 웹 사이트에는 사용자가 StudentList에서 학생을 검색 할 수있는 검색 기능이 있으며 결과가 DataGrid에 표시됩니다. 사용자가 목록에서 학생을 선택하면 저널 입력 상자가 나타납니다. 저널 항목 팝업 상자를 채우고 제출 버튼을 클릭하면 저널 항목을 DataGrid에서 선택된 학생 ID에 연결된 JournalEntries 테이블에 입력해야합니다.
protected void SearchGrid_SelectedIndexChanged(object sender, EventArgs e)
{
FNameLabel.Text = SearchGrid.SelectedRow.Cells[1].Text;
LNameLabel.Text = SearchGrid.SelectedRow.Cells[2].Text;
string constr = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Sites\Network2\nrsh\App_Data\myDB.mdb";
string cmdstr = "SELECT StudentID FROM StudentList WHERE = SearchGrid.SelectedRow.Cells[3].Text AND INSERT into JournalEntries (Topic, SubTopic, Summary, Date, Notes) values (@Topic, @SubTopic, @Summary, @Date, @Notes)";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand com = new OleDbCommand(cmdstr, con);
con.Open();
//The following fields are added from the journal entry form to the corresponding database fields
com.Parameters.AddWithValue("@Topic", ddlTopic.Text);
com.Parameters.AddWithValue("@SubTopic", txtSubTopic.Text);
com.Parameters.AddWithValue("@Date", txtDate.Text);
com.Parameters.AddWithValue("@Summary", txtSummary.Text);
com.Parameters.AddWithValue("@Notes", txtNotes.Text);
com.ExecuteNonQuery();
con.Close();
}
그래서 논리에 대한 제 생각이지만 SQL에 대해 많이 알지 못하기 때문에 아마 완전히 잘못되었습니다. 어떤 도움이라도 좋을 것입니다.
정확한 진술은 어떻게 생겼을까요? – Michael
수정 사항을 확인하십시오. 나는 전체 코드가 보이지 않기 때문에 .......... 나는 추측하고있다. – granadaCoder
또한, 생각했던대로하지 않는 SQL 문을 문제를 해결할 때 C# 코드에 포함시켜 문제를 복잡하게 만들지 마십시오.SQL Server Management Studio를 열고 쿼리를 직접 입력하면됩니다. 그렇게하면 SQL을 둘러싼 모든 C# 장치보다 SQL 자체에 집중할 수 있습니다. – catfood