what is wrong?

  • Thread starter Daniel Sélen Secches
  • Start date
D

Daniel Sélen Secches

I was trying to make a simple dataReader....

Sub projets()
Dim conn As New OleDbConnection(connstring)
Dim dr As OleDbDataReader()
Dim cmd As New OleDbCommand()
cmd.CommandText = "select * from projeto order by nome"
cmd.Connection = conn
conn.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
End Sub

what is wrong about it?

--
tks.

Daniel Sélen Secches
CWD Web Internet.
www.cwd.com.br
 
C

Cor

Hi Daniel,
Sub projets()
Dim conn As New OleDbConnection(connstring)
Dim dr As OleDbDataReader()
Dim cmd As New OleDbCommand()
cmd.CommandText = "select * from projeto order by nome"
cmd.Connection = conn
conn.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
End Sub

what is wrong about it?

Is this the end

It can go like this

Dim rdr As SqlDataReader
rdr = cmd.ExecuteReader()
Dim id As String
Dim pr As String
While rdr.Read()
id = rdr.GetInt32(0).ToString
pr = rdr.GetString(1)
End While
rdr.Close()

A little bit stupid like this because the id and pr is all the time
overwritten, but it just a sample.

I hope this helps?

Cor
 
L

Lee Moody

I'm wondering if you are setting the connection of the
oledbcommand object to a closed connection. Try conn.open
first then set cmd.connection=conn.

-Lee
 
D

Daniel Sélen Secches

that error....

Value of type 'System.Data.OleDb.OleDbDataReader' cannot be converted to
'1-dimensional array of System.Data.OleDb.OleDbDataReader'.
 
D

Daniel Sélen Secches

i've tried it but nothing ... : <

"Lee Moody" <[email protected]> escreveu na mensagem
I'm wondering if you are setting the connection of the
oledbcommand object to a closed connection. Try conn.open
first then set cmd.connection=conn.

-Lee
 
D

Daniel Sélen Secches

i'm getting the error on cmd.executeReader(...) the "blue line" appears
under the cmd.executeReader()

Value of type 'System.Data.OleDb.OleDbDataReader' cannot be converted to
'1-dimensional array of System.Data.OleDb.OleDbDataReader'.


I was just trying to do the exemple that a got from a book.... the exemple
is whit SQL server and i changed it to access DB

here is the book exemple:
=============================================
Dm cn As New SqlConnection("Server=(local)\NetSDK;DataBase=pubs;Integrated
Security=SSPI")
Dim dr As SqlDataReader
Dim cmd As New SqlCommand()
With cmd
.CommandText = "Select au_lname, au_fname from Authors"
.Connection = cn
End With
cn.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim strName As String
While dr.Read
' Add the items to the ListBox1 control
strName = dr("au_lname") & ", " & dr("au_fname")
MessageBox.Show(strName)
End While
cn.Close()
=============================================
tks again
 
C

CJ Taylor

Dim dr As OleDbDataReader()

take off the ()

Daniel Sélen Secches said:
i'm getting the error on cmd.executeReader(...) the "blue line" appears
under the cmd.executeReader()

Value of type 'System.Data.OleDb.OleDbDataReader' cannot be converted to
'1-dimensional array of System.Data.OleDb.OleDbDataReader'.


I was just trying to do the exemple that a got from a book.... the exemple
is whit SQL server and i changed it to access DB

here is the book exemple:
=============================================
Dm cn As New SqlConnection("Server=(local)\NetSDK;DataBase=pubs;Integrated
Security=SSPI")
Dim dr As SqlDataReader
Dim cmd As New SqlCommand()
With cmd
.CommandText = "Select au_lname, au_fname from Authors"
.Connection = cn
End With
cn.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim strName As String
While dr.Read
' Add the items to the ListBox1 control
strName = dr("au_lname") & ", " & dr("au_fname")
MessageBox.Show(strName)
End While
cn.Close()
=============================================
tks again
 
A

_Andy_

that error....

Value of type 'System.Data.OleDb.OleDbDataReader' cannot be converted to
'1-dimensional array of System.Data.OleDb.OleDbDataReader'.


Get rid of the "()"
 
D

Daniel Sélen Secches

ohh god,,,, ,that was a stupid error..... i don't belive that

Now it's works....

tks again.....
 
D

Daniel Sélen Secches

ohh god,,,, ,that was a stupid error..... i don't belive that

Now it's works....

tks again.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top