hi, I have a vb program that wants to retrieve data from MySQL dbase.

this code is working fine :

Dim vDATE As String 

vDATE = mDATE.ToString("yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture) 
Dim connstring As String = "server=xxx.xxx.x.xx;database=dbname;uid=idko;Pwd=passko" 
Using con As New MySqlConnection(connstring) 
    con.Open() 
    Dim query As String = "SELECT issue_date, inc_date, exp_date, total FROM table_name WHERE ISSUE_DATE = @DATE " 
    Dim MYSQLCMD As New MySqlCommand(query, con) 
    MYSQLCMD.Parameters.AddWithValue("@DATE", vDATE) 
    Dim reader As MySqlDataReader = MYSQLCMD.ExecuteReader 
    While reader.Read 
        MessageBox.Show(reader.GetString(0) & vbCr & reader.GetString(1) & vbCr & reader.GetString(2) & vbCr & reader.GetString(3)) 
    End While 
End Using 

but the code below give me an error that says "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"

Dim vDATE As String 

vDATE = mDATE.ToString("yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture) 
Dim connstring As String = "server=xxx.xxx.x.xx;database=dbname;uid=idko;Pwd=passko" 
Using con As New MySqlConnection(connstring) 
    con.Open() 
    Dim query As String = "SELECT ref_no,name, address,zipcode FROM table_name WHERE ISSUE_DATE = @DATE " 
    Dim MYSQLCMD As New MySqlCommand(query, con) 
    MYSQLCMD.Parameters.AddWithValue("@DATE", vDATE) 
    Dim reader As MySqlDataReader = MYSQLCMD.ExecuteReader 
    While reader.Read 
        MessageBox.Show(reader.GetString(0) & vbCr & reader.GetString(1) & vbCr & reader.GetString(2) & vbCr & reader.GetString(3)) 
    End While 
End Using 

any help would be greatly appreciated.

thank you.

Recommended Answers

All 8 Replies

Next time, use the code formatting feature of the forum.

As it stands I can't guess your database design. What if there is no ref_no,name, address,zipcode in the columns?

Hi, this is my database design :

issue_date - date
inc_date - date
exp_date - date
total - double
ref_no - varchar(9)
name - varchar(50)
address - varchar(100)
zipcode - varchar(4)

Thanks.

Is this running on a localhost server or an external server?

It sounds like a firewall/port problem that is blocking your request. Need some more info unfortunately.

its on external server, however, why is my first query (issue_date, inc_date, exp_date, total) runs ok but when I select ref_no,name, address,zipcode it gives me that error.

Thank you.

I missed that, my apologies.

The 1st one works because your select statement is 100% correct. Your second one is incorrect in that you refer to Issue_date as a pointer to select but you are not referencing tis in the 1st part. This measn your connection connects, awaits a return but nothing happens, returns a time out.

Change the following...

Dim query As String = "SELECT ref_no,name, address,zipcode FROM table_name WHERE ISSUE_DATE = @DATE "

TO

Dim query As String = "SELECT ISSUE_DATE, ref_no,name, address,zipcode FROM table_name WHERE ISSUE_DATE = @DATE "

This will return a positive row if it exist or land you with an empty row.

hi,

I did what you suggested but still getting that error. is it me or its just weird that when i select varchar data type fields i get that error but when selecting other data type it runs ok.

Thanks.

ISSUE_DATE should be in lower case - issue_date

What exactly gets returned by @DATE, is it an actual date? Where do you get the value from by using this?

will try to change it to lower case.

@DATE is an actual date, (ex. 2019/01/15), i have a listview of number of transactions group per day (ex. for the month of january) , when i double click on a particular date another listview will show all of the fields/records in my query statement.

my listview looks like this :

day # records
2019/01/02 20
2019/01/05 15
2019/01/25 5
2019/01/31 10

Thank you very much for your time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.