Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I read a link from mysql databse???
#1
Hello,
I watched all the brandonio's video tutorials on youtube..

I worked according to his video tutorials....

Now at one stage I got a problem here...I made an updater for my software using UpdateVB component and wants to get the version.txt links and SFX download link from the database...I tried something but it doesn't work....

What have I tried:
[code2=vbnet]Imports MySql.Data.MySqlClient
Public Class updater
Public conn As MySqlConnection

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
conn = New MySqlConnection(ServerString)
Try
conn.Open()
Dim sqlquery As String = "SELECT vlink, dlink, ftpu, dtpp FROM updater"
Dim data As MySqlDataReader
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
command.CommandText = sqlquery
command.Connection = conn
adapter.SelectCommand = command
data = command.ExecuteReader
While data.Read()
If data.HasRows() Then
Dim vlink As String = data(1).ToString
Dim dlink As String = data(2).ToString
Dim ftpu As String = data(3).ToString
Dim ftpp As String = data(4).ToString
End If
End While
UpdateVB1.checkforupdate("vlink", "0.0.9", "dlink", "ftpu", "ftpp", showUI:=True)
data.Close()
conn.Close()
Catch ex As Exception
End Try
End Sub
End Class[/code2]

but by my codes the updater didn't response at all and I also get no error...

Please help me how can I do this or by which codes I can solve my problem...I am a beginner in vb.net..

Please help me...

Thanks in advance.....
#2
Someone plzzz help me.......
#3
Well, your main problem is that you want to use the information retrieved from the database, right? Well, in order to actually use these variables, you must declare them outside your "while" loop. Since they are declared outside your while loop, you are not able to use them in your checkForUpdates call. That's why you were forced to put quotation marks around them, turning them into meaningless Strings, if you will.

Then, once you've moved the creation of your variables, you can directly access them in your checkForUpdates call. See the fixed code below.

[code2=vbnet]Imports MySql.Data.MySqlClient
Public Class updater
Public conn As MySqlConnection

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
conn = New MySqlConnection(ServerString)
Try
conn.Open()
Dim sqlquery As String = "SELECT vlink, dlink, ftpu, dtpp FROM updater"
Dim data As MySqlDataReader
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
command.CommandText = sqlquery
command.Connection = conn
adapter.SelectCommand = command
data = command.ExecuteReader
Dim vlink As String = ""
Dim dlink As String = ""
Dim ftpu As String = ""
Dim ftpp As String = ""
While data.Read()
If data.HasRows() Then
vlink = data(1).ToString
dlink = data(2).ToString
ftpu = data(3).ToString
ftpp = data(4).ToString
End If
End While
UpdateVB1.checkforupdate(vlink, "0.0.9", dlink, ftpu, ftpp, True)
data.Close()
conn.Close()
Catch ex As Exception
End Try
End Sub[/code2]
My Blog | My Setup | My Videos | Have a wonderful day.
#4
bro your corrected c0de also don't worked for me....
is it a problem in my database structure????

if so then please provide me the structure on how i can make the database to get the link from it.

Thanks in advance.....
#5
First of all my opinion is that you are trying to make a program way above your beginer level.Stick to "hello world" application until you learn something other than copy/paste

Second using a Try/Catch block without reporting something if an error ocurs is usless because the program ignores the problem but the error remains. Simply add a msgbox at the end of the try/catch block and copy/paste the error here in order to get proper help.

And just in case you have no clue as what i said above here's the code:

[code2=vbnet]Catch ex As Exception
Msgbox(ex.ToSting)
End Try[/code2]
Sssssssssoftware developer...
#6
bro if u guys don't help us then h0w we can learn s0mething???

and i am trying ur code to get the informati0n 0f the exact err0r.....
#7
i have n0w pr0vided this c0de in the updater f0rm:
Code:
Imports MySql.Data.MySqlClient
Public Class updater
    Public conn As MySqlConnection

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        conn = New MySqlConnection(ServerString)
        Try
            conn.Open()
            Dim sqlquery As String = "SELECT vlink, dlink, ftpu, dtpp FROM updater"
            Dim data As MySqlDataReader
            Dim adapter As New MySqlDataAdapter
            Dim command As New MySqlCommand
            command.CommandText = sqlquery
            command.Connection = conn
            adapter.SelectCommand = command
            data = command.ExecuteReader
            Dim vlink As String = ""
            Dim dlink As String = ""
            Dim ftpu As String = ""
            Dim dtpp As String = ""
            While data.Read()
                If data.HasRows() Then
                    vlink = data(1).ToString
                    dlink = data(2).ToString
                    ftpu = data(3).ToString
                    dtpp = data(4).ToString
                End If
            End While
            UpdateVB1.checkforupdate(vlink, "0.0.9", dlink, ftpu, dtpp, True)
            data.Close()
            conn.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

but it is saying an error in the msgbox....
The snapshot of the error and my sql database snapshot is given below:

Error:
[Image: 10zp7w2.png]

Database:
[Image: 21ootpw.png]


Please help me why this problem occurs.....
#8
mnxford Wrote:bro if u guys don't help us then h0w we can learn s0mething???
So you want to learn ? ok look in the msgbox it says the error occurs on line 26 and by my calculations that line is this one
[code2=vbnet]ftpp = data(4).ToString[/code2]
second information you can get from the error is the type "IndexOutOfRange" that means that index 4 does not exist in your table. i suggest the folowing corection to your code
[code2=vbnet]vlink = data(0).ToString
dlink = data(1).ToString
ftpu = data(2).ToString
ftpp = data(3).ToString[/code2]

Try this code, if you get an error again and still want to learn the next lesson is debugging.

Here's how to debug:

Put a breakpoint at the begining of the try/catch block, you can do that by clicking next to were you see the green or yellow line, a red dot shold apear.

When the breakpoint is hit and you are see the code again press F10 , that will take you through the code step by step, line by line.

Check the values, you can do taht in 2 ways , either by going to the locals tab in the bottom part of visual studio or by hovering over the strings with the mouse.Check the 4 strings(vlink,dlink,ftpu,ftpp) and see if the right values are assigned. Beware that the values are assigned after the yellow line has passed the string.
Sssssssssoftware developer...
#9
Thank You so much snake and brandonio bro....
i have fixed the problem....
i hope you guys will be there to help me in my other topics...

Please close the topic...
Thanks again...
#10
I'm glad to hear it! Just know that in order to become more skilled in programming, you're going to need to dedicate some time to learning the material. But just for record-keeping purposes, what exactly was the problem and how did you solve it?
My Blog | My Setup | My Videos | Have a wonderful day.


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I use Listview to delete MySQL DB records kismetgerald 10 33,858 11-28-2012, 05:19 PM
Last Post: brandonio21
  [SOLVED] MySQL Update Query - What am I doing wrong? kismetgerald 11 43,319 10-18-2012, 07:16 PM
Last Post: brandonio21
  How do I fill my form with MySQL data based on Combobox? kismetgerald 8 26,709 10-14-2012, 09:05 PM
Last Post: brandonio21
  Read certain lines brco900033 3 14,633 09-26-2012, 03:56 PM
Last Post: brandonio21
  Read and delete lines brco900033 6 22,569 09-16-2012, 09:38 AM
Last Post: brandonio21
  Help with creating an INSERT statement using MySQL kismetgerald 4 16,757 08-30-2012, 03:03 PM
Last Post: brandonio21
  MySQL Database Issue Moldraxian 7 29,054 08-13-2012, 08:58 PM
Last Post: brandonio21
  MySql Database Queries in VB.Net Moldraxian 6 22,381 07-26-2012, 03:44 PM
Last Post: Moldraxian
  How to Package MySql Connector and MySql Program? Moldraxian 3 14,754 07-20-2012, 12:23 PM
Last Post: brandonio21
  MySql Help Blackrobot 3 14,621 04-06-2012, 03:49 AM
Last Post: xolara

Forum Jump:


Users browsing this thread: 1 Guest(s)