从 DataTableReader 获取数据时出错
Error In getting data from DataTableReader
正如标题所说,我无法从数据table获取我的数据,这是因为我使用了 innerjoin ,如果我只使用一个 table 它工作正常,只要我把 inner加入它给我这个错误:
似乎是 sql 句子中的错误,因为它 return 对 datareader 没有任何价值。
"System.InvalidOperationException: 'O DataTableReader é inválido para o DataTable atual ''.'"
这里是代码
Dim sql As String = "SELECT * FROM TOTAIS INNER JOIN FAT_PRODS ON TOTAIS.ID_FAT=FAT_PRODS.ID_FAT WHERE FAT_PRODS.ID_FAT=" + DataGridView1.SelectedRows(0).Cells(1).Value.ToString + ""
Dim dadosretornados As System.Data.DataTableReader = buscadadosacess(sql)
If dadosretornados.HasRows Then
While dadosretornados.Read
MsgBox(dadosretornados("ID_PROD"))
End While
End If
这里是函数buscadados
Function buscadadosacess(sql As String)
oConn.ConnectionString = strConn
oConn.Open()
If oConn.State = ConnectionState.Open Then
ACommand = New OleDbCommand(sql, oConn)
'define um dataAdapter
AAdapter = New OleDbDataAdapter()
AAdapter.SelectCommand = ACommand
'define e preenche um DataTable com os dados
ATabela = New DataTable()
AAdapter.Fill(ATabela)
' associar campos a base de dados
xy = ATabela.CreateDataReader
' Ler da tabela
'linha = ACommand.ExecuteReader
End If
'Tipo de dados incorrecto na expressão de critérios.'
Return xy
End Function
谢谢大家 <3
错误只是一个“.”在 SQL 句子中,这里是 SQL 句子正确:
Dim sql As String = "select totais.id_fat,totais.valor_siva,totais.iva,totais.valortotal,totais.data,totais.nome_cliente,fat_prods.id_fat,fat_prods.id_prod,fat_prods.quantidade,fat_prods.preco,fat_prods.id_cliente,fat_prods.descricao from totais INNER JOIN fat_prods ON totais.id_fat=fat_prods.id_fat WHERE totais.id_fat=" + valor.ToString + ""
感谢大家的帮助
正如标题所说,我无法从数据table获取我的数据,这是因为我使用了 innerjoin ,如果我只使用一个 table 它工作正常,只要我把 inner加入它给我这个错误:
似乎是 sql 句子中的错误,因为它 return 对 datareader 没有任何价值。
"System.InvalidOperationException: 'O DataTableReader é inválido para o DataTable atual ''.'"
这里是代码
Dim sql As String = "SELECT * FROM TOTAIS INNER JOIN FAT_PRODS ON TOTAIS.ID_FAT=FAT_PRODS.ID_FAT WHERE FAT_PRODS.ID_FAT=" + DataGridView1.SelectedRows(0).Cells(1).Value.ToString + ""
Dim dadosretornados As System.Data.DataTableReader = buscadadosacess(sql)
If dadosretornados.HasRows Then
While dadosretornados.Read
MsgBox(dadosretornados("ID_PROD"))
End While
End If
这里是函数buscadados
Function buscadadosacess(sql As String)
oConn.ConnectionString = strConn
oConn.Open()
If oConn.State = ConnectionState.Open Then
ACommand = New OleDbCommand(sql, oConn)
'define um dataAdapter
AAdapter = New OleDbDataAdapter()
AAdapter.SelectCommand = ACommand
'define e preenche um DataTable com os dados
ATabela = New DataTable()
AAdapter.Fill(ATabela)
' associar campos a base de dados
xy = ATabela.CreateDataReader
' Ler da tabela
'linha = ACommand.ExecuteReader
End If
'Tipo de dados incorrecto na expressão de critérios.'
Return xy
End Function
谢谢大家 <3
错误只是一个“.”在 SQL 句子中,这里是 SQL 句子正确:
Dim sql As String = "select totais.id_fat,totais.valor_siva,totais.iva,totais.valortotal,totais.data,totais.nome_cliente,fat_prods.id_fat,fat_prods.id_prod,fat_prods.quantidade,fat_prods.preco,fat_prods.id_cliente,fat_prods.descricao from totais INNER JOIN fat_prods ON totais.id_fat=fat_prods.id_fat WHERE totais.id_fat=" + valor.ToString + ""
感谢大家的帮助