473,568 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with DataReader and MySQL .NET connector.. Please Help!

Teo
Hi!!
I have been trying to fix an error I keep getting on my VB.NET code.
For some reason, I get an error saying "Invalid attempt to access a field
before calling Read()" everytime. As you can see in my code below, I created
the connection, connection string, etc and I opened the connection, executed
the reader and then called the datareader.read () before any variable
assignment below.
I keep getting that error and I don't know why! I am going crazy.
Please check my code below:

Dim login As String = txtlogin.Text
Dim pass As String = txtpass.Text

Dim strConn As String
strConn = "host=201.218.2 39.10; user id=acarsuser; password=xxxxx;
database=acarss ystem"
Dim conn As New MySqlConnection (strConn)
Dim SQLCode As String
SQLCode = "SELECT DISTINCT pilot_id,name, password FROM pilot WHERE name='"
+ login + "' AND password = '" + pass + "'"
Dim datareader As MySqlDataReader
Dim Cmd As New MySqlCommand(SQ LCode, conn)
Try
conn.Open()
datareader = Cmd.ExecuteRead er

datareader.Read ()

Dim userID As String = datareader("nam e").ToString
Dim userpassword As String = datareader("pas sword").ToStrin g
If userID = login And userpassword = pass Then
'Creo la conexion para notificar al DB que el piloto esta Online
Dim pilotID As Integer
pilotID = datareader("pil ot_id").ToStrin g
Dim strConn1 As String
strConn1 = "host=201.218.2 39.10; user id=acarsuser; password=xxxxx;
database=acarss ystem;PORT=3306 "
Dim conn1 As New MySqlConnection (strConn1)
Dim SQLCode1 As String
SQLCode1 = "INSERT INTO acars_pilot (pilot_id) VALUES (" + pilotID + ")"
Dim myCommand As MySqlCommand
conn1.Open()
myCommand = New MySqlCommand(SQ LCode1, conn1)
myCommand.Execu teNonQuery()
conn1.Close()
Me.Hide()
AcarsMain.Show( )
Else
'Aviso que el usuario no existe
MsgBox("The user and password you supplied is not on the system. Please try
again.", MsgBoxStyle.Exc lamation)
End If

conn.Close()
Catch ex As Exception
MsgBox("Connect ion to ACARS server Unsuccessfull. Please try again later." &
ex.Message, MsgBoxStyle.OkO nly)

End Try
\\

For some reason the data reader doesn't work at all.No records are returned
and I get no message as I have in the code.
Any suggestions?
Thanks,
Teo
Dec 23 '07 #1
0 2877

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3665
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the mysql- connector-java-2.0.14-bin.jar in commons/lib. The application runs normally, and usually about once or twice a day I get this exception...
0
2557
by: Blah Blah | last post by:
i just thought i'd shoot out a quick email on problems i've been having with utf-8 in moving from 4.1.0 to 4.1.1. (please note that because i am using UTF-8 as my default character set, i compiled from source rather than using a premade binary) i know that i'm working with alpha software - this is more of a warning/sharing of knowledge...
3
2283
by: Mike | last post by:
Using MS Access XP standard install (no Jet or MDAC updates applied yet) as front end, MySQL 4.0 as backend and MySQL ODBC connector version 3.51. When pasting multiple records into the database either in a form or directly in the table, all records / fields display #deleted in each column. This only happens when pasting multiple records,...
0
1444
by: TB | last post by:
Hi All: This news group is proving to be great help on my path towards mastering ASP.NET thanks to all of you helpful souls out there. I am looking forward to the day when I can contribute with a few ounces of hard-won knowledge as well. Meanwhile I have this (hopefully small) problem. On my local computer where I am developing a web...
5
2338
by: TB | last post by:
Hi All: This news group is proving to be great help on my path towards mastering ASP.NET thanks to all of you helpful souls out there. I am looking forward to the day when I can contribute with a few ounces of hard-won knowledge as well. Meanwhile I have this (hopefully small) problem.
3
1411
by: JJ | last post by:
I am a newbie to mySQL. I am developing an ASP .net Web site with mySQL as the database (of products), using vb .net 2003. Can anyone point me in the direction of a good book (or in fact ANY book) on using mySQL with asp .net ?? I am having trouble working out: 1. What type of connector to use to my database (i.e. ODBC or mySQL's .net...
5
2720
by: Ananthu | last post by:
Hi I have done all the codings part for connecting mysql server with java application but when i try to compile,the compilation is successful and during execution i get the following message, Exception in thread "main" java.lang.NoClassDefFoundError: MysqlConnect Coding Part: import java.sql.*; import java.lang.*;
1
2136
by: sethupnr | last post by:
when i'm using a simple JSP-mysql code it shows some HTTP status 500 error.But simple JSP program without databse is running , Please help how to solve this problem. I'm new to JSP. my configurations are... i installed j2sdk in C:\j2sdk1.4.2_16 then installed jakarte-tomcat in C:\Program Files\Apache Tomcat 4.0 folder copied...
6
2838
by: shivapadma | last post by:
i want to access mysql database server from jsp program for this i downloaded mysql-connector-java-3.1.14.zip mysql-connector-java-3.1.14 folder contains mysql-connector-java-3.1.14-bin.jar file. then the mysql-connector-java-3.1.14-bin.jar is placed in classpath after that,i started tomcat server and executed the jsp program
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.