Problems selecting from a db

Problems selecting from a db

Postby tomekz28 » Mon 21 Mar 2005 16:31

Hi,

I am trying to select a value from a dtatabase using mysqlcommand, but I always get an error that ' No data exists for the row/column.'

Here's my code:
Me.com_cdl = New CoreLab.MySql.MySqlCommand
Me.com_cdl.CommandTimeout = 30
Me.com_cdl.Connection = Me.con_cdl
Me.com_cdl.Name = "com_cdl"
con_cdl.Open()
Try
com_cdl.CommandText = "SELECT * from tblpersonal"
com_cdl.FetchAll = True
com_cdl.ExecuteReader()
While com_cdl.ExecuteReader.Read()

Console.WriteLine(com_cdl.ExecuteReader.GetInt32(0).ToString())

End While

Now, I have tried many ' com_cdl.ExecuteReader, like getvalue, get string, item, hasrows - only 'hasrows' returns true, everything else gives me the error I mentioned above.

I am new to this so perhaps I am missing something obvious!

Will be grateful for any ideas!

- Tom
tomekz28
 

Postby Serious » Tue 22 Mar 2005 12:34

Please try to use this simple code fragment. It is based on "test" schema included in MySQLDirect .NET distribution package (see Program Files\CoreLab\MySQLDirect.NET\Samples\tables.sql)
Code: Select all
dim connection as MySqlConnection = new MySqlConnection("host=localhost;database=test;user id=root;")
dim cmd as MySqlCommand = new MySqlCommand("select * from dept", connection)
dim reader as MySqlDataReader 
connection.Open()
try
  reader = cmd.ExecuteReader()
  while reader.Read()
    Console.WriteLine(reader.GetInt32(0).ToString())
  end while
finally
  reader.Close()
  connection.Close()
end try
Serious
 


Return to dotConnect for MySQL