누군가 내가 내 레코드를 MS Access에 삽입 할 수없는 이유를 설명 할 수 있습니까? 나는 인위적으로 가능한 모든 것을 시도했지만, 내가해야 할 일을시키지 않을 것이다. 내가 뭘 해야하는지 내 C 샤프 프로그램에서 작성된 기록을 허용하고 내 MS 액세스에 값을 삽입합니다 버튼을 누르면됩니다.MSAccess에 레코드 삽입하기
void Insert_Record(object s, EventArgs e)
{
string dbconnection = "Provider=Microsoft.ACE.OLEDB.12.0;" + @"data source =BookCSharp.accdb";
string dbcommand = "INSERT INTO BookKey, Title, Pages from Books;";
OleDbConnection conn = new OleDbConnection(dbconnection);
OleDbCommand comm = new OleDbCommand(dbcommand, conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(comm);
conn.Open();
adapter.Fill(ds, "Books");
conn.Close();
DataTable dt = ds.Tables[0];
//define a new record and place it into a new DataRow
DataRow newRow = dt. NewRow();
newRow["BookKey"] = txtBookKey.Text;
newRow["Title"] = txtTitle.Text;
newRow["Pages"] = txtPages.Text;
//add the new DataRow to DataTable
dt.Rows.Add(newRow);
//update DB
adapter.Update(ds, "Books");
//accept changes
ds.AcceptChanges();
//update listBox1
lstDisplayBooks.Items.Clear();
foreach (DataRow row in ds.Tables[0].Rows)
{
lstDisplayBooks.Items.Add(row["BookKey"] + " " + row["Title"] + " (" + row["Pages"] + ")");
}
txtBookKey.Enabled = false;
txtBookKey.Text = " ";
txtTitle.Enabled = false;
txtTitle.Text = " ";
txtPages.Enabled = false;
txtPages.Text = " ";
btnInsert.Enabled = false;
}
PK 열을 정의 했습니까? IIRC 액세스가 ID 열을 지원하지 않습니다. – BradleyDotNET
받고있는 오류 메시지를 게시 할 수 있습니까? – paqogomez
@BradleyDotNET 예, 지원됩니다. 액세스는 "일련 번호"라고합니다. –