as title say's im not being able to get my data from datatable, it's because im using innerjoin , if i only use one table it work's fine, as soon as i put inner join it gives me this error :
seems like the error its in sql sentence, because it don't return any value to datareader.
"System.InvalidOperationException: 'O DataTableReader é inválido para o DataTable atual ''.'"
here goes the code
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
here is the function 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
thanks guys <3
the error was just a "." in the SQL Setence, here it goes the SQL SENTENCE Correct:
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 + ""
thanks for all the help