2013-07-03 4 views
0

vb.net을 사용하여 액세스 2010 databse에 쓰려고합니다. 나는 그것을 작동 시켰지만 이전 데이터베이스를 지우고 새 데이터베이스를 만들어야 만했습니다. 작동하지 않습니다. 여기 내가 가지고있는 코드는 : 나는 새로운 데이터 집합, TableAdpater했습니다, 나는 또한 새로운 데이터베이스에 대한 연결을 만들어 내 새 데이터베이스를 만든Access 2010 데이터베이스에 쓰기

Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Forte\Fortedb.accdb" 
    Dim cnn As New OleDbConnection(ConnString) 
    cnn.Open() 

    'Naming the new Row in Query1. 
    Dim newQuery1Row As FortedbDataSet.Query1Row 
    newQuery1Row = Me.FortedbDataSet1.Query1.NewQuery1Row() 

    'Making the first row the date. 
    newQuery1Row.ProdDate = GlobalVariables.mdbProdDate 
    newQuery1Row.BaleLine = GlobalVariables.mdbBaleLine 
    newQuery1Row.BaleNumber = GlobalVariables.mdbBaleNumber 
    newQuery1Row.GrossWeight = GlobalVariables.mdbGrossWeight 
    newQuery1Row.AirDry = GlobalVariables.mdbAirDry 
    newQuery1Row.InvoiceWeight = GlobalVariables.mdbInvoiceWeight 

    'Adding the row to the table. 
    Me.FortedbDataSet1.Query1.Rows.Add(newQuery1Row) 

    cnn.Close() 

    'Saving the row in Access. 
    Me.Query1TableAdapter.Update(Me.FortedbDataSet1.Query1) 

. 나는 뭔가를 간과해야합니다.

+1

"작동하지 않음"을 정의하십시오. 예외 메시지는 무엇입니까? 스택 트레이스? – EkoostikMartin

+0

오류 메시지가 표시되지 않습니다. 그것은 잘 실행되지만 내 데이터베이스에 저장되지 않습니다. 나는 무엇이 일어나고 있는지 완전히 확신하지 못한다. –

+0

데이터 세트 및 테이블 어댑터 정의 방법을 알지 못해서 알기가 어렵습니다. – EkoostikMartin

답변

0

나는 그것을 알아 냈다. 문제를 해결하기 위해 SQL 문을 사용하기로 결정했습니다.

Dim connection As OleDb.OleDbConnection mystr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Forte\Fortedb.accdb" connection = New OleDb.OleDbConnection(mystr) connection.Open() 'Inserting the data into the database. mydb = "INSERT INTO b_forte (ProdDate, BaleLine, BaleNumber, GrossWeight, AirDry, InvoiceWeight) VALUES ('" & mdbProdDate & "', '" & mdbBaleLine & "', '" & mdbBaleNumber & "', '" & mdbGrossWeight & "', '" & mdbAirDry & "', '" & mdbInvoiceWeight & "')" Dim run = New OleDb.OleDbCommand Try run = New OleDbCommand(mydb, connection) run.ExecuteNonQuery() connection.Close()