2013-05-01 2 views
0

내 액세스 데이터베이스의 데이터가 뷰에 표시되고 있습니다. 응용 프로그램을 실행할 때마다 da2.Fill (ds2, "Inventory") 바로 전에 오류가 발생합니다. 내가 사용하고있는 테이블을 제품 및 인벤토리라고합니다. 내가 생각할 수있는 모든 것을 시험해 보았습니다. 어떤 힌트/소스가 왜 매우 애통 해 보였습니다.DataGridView 채우기

Public Class Form1 
Dim con As New OleDb.OleDbConnection 
Dim ds As New DataSet ' in memory version of database 
Dim da As OleDb.OleDbDataAdapter 
Dim sql As String 

Dim ds2 As New DataSet 
Dim da2 As OleDb.OleDbDataAdapter 
Dim sql2 As String 

Dim strProdNo As String 
Dim inc, MaxRows As Integer 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    'TODO: This line of code loads data into the 'ComputerWarehouseProjectDataSet.Product' table. You can move, or remove it, as needed. 
    'Me.ProductTableAdapter.Fill(Me.ComputerWarehouseProjectDataSet.Product) 
    con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = ComputerWarehouseProject.mdb" 
    con.Open() 'put a try catch around this 
    sql = "SELECT * FROM Product order by ProdNo" 
    da = New OleDb.OleDbDataAdapter(sql, con) 
    da.Fill(ds, "ComputerWarehouseProject") 
    con.Close() 
    MaxRows = ds.Tables("ComputerWarehouseProject").Rows.Count 
    inc = 0 
    NavigateRecords() 

End Sub 
Private Sub NavigateRecords() 
    Try 
     txtId.Text = ds.Tables("ComputerWarehouseProject").Rows(inc).Item(0) 
     txtPart.Text = ds.Tables("ComputerWarehouseProject").Rows(inc).Item(1) 
     txtQoh.Text = ds.Tables("ComputerWarehouseProject").Rows(inc).Item(3) 
     txtCost.Text = ds.Tables("ComputerWarehouseProject").Rows(inc).Item(4) 
     'MessageBox.Show("Works 1") 
     txtSugPrice.Text = ds.Tables("ComputerWarehouseProject").Rows(inc).Item(5) 
     cbProd.Text = ds.Tables("ComputerWarehouseProject").Rows(inc).Item(0) & " " & ds.Tables("ComputerWarehouseProject").Rows(inc).Item(1) 
     'MessageBox.Show("Works 2") 
     txtRecBeg.Text = (inc + 1).ToString 
     'MessageBox.Show("Works 3") 
     txtRecEnd.Text = ds.Tables("ComputerWarehouseProject").Rows.Count.ToString 
     'MessageBox.Show("Works 4") 
     bldInv() 
     'MessageBox.Show("Works 5") 
    Catch 
     MessageBox.Show("Data Error! Cannot Navigate to Selected Record at position " & inc.ToString) 

    End Try 

End Sub 
Private Sub bldInv() 

    strProdNo = ds.Tables("ComputerWarehouseProject").Rows(inc).Item(0) 
    sql2 = "Select * from Inventory where ProdNo = " + strProdNo 
    ds2.Clear() 
    MessageBox.Show(sql2) 
    da2 = New OleDb.OleDbDataAdapter(sql2, con) 

    MessageBox.Show("Right before fill") 
    da2.Fill(ds2, "Inventory") 


    dgvInv.DataSource = ds2.Tables("Inventory") 
    dgvInv.AutoResizeColumns() 


End Sub 
+0

를? – DeanOC

+0

데이터 세트를 데이터 테이블 개체로 변경해보십시오. 당신의 문제는 당신이 테이블의 이름을 바꾸려고한다는 것입니다. – SSS

+0

또는 쿼리를 "SELECT * FROM Product From ProdNo에 의한 ComputerWarehouseProject 주문"으로 변경해보십시오. – SSS

답변

0

당신이 시도 할 수 : 당신은 Access 데이터베이스에 대해 직접 SQL2에서 SQL을 실행할 때, 다시 기록을 얻을

da.Fill(ds) 
con.Close() 
MaxRows = ds.Tables(0).Rows.Count 
관련 문제