How can I read a link from mysql databse??? - Printable Version +- BP Forums (https://bpforums.info) +-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55) +--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56) +---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8) +----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=9) +----- Thread: How can I read a link from mysql databse??? (/showthread.php?tid=760) |
How can I read a link from mysql databse??? - mnxford - 03-19-2013 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..... Re: How can I read a link from mysql databse??? - mnxford - 03-23-2013 Someone plzzz help me....... Re: How can I read a link from mysql databse??? - brandonio21 - 03-24-2013 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] Re: How can I read a link from mysql databse??? - mnxford - 03-25-2013 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..... Re: How can I read a link from mysql databse??? - Snake_eyes - 03-26-2013 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] Re: How can I read a link from mysql databse??? - mnxford - 03-26-2013 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..... Re: How can I read a link from mysql databse??? - mnxford - 03-26-2013 i have n0w pr0vided this c0de in the updater f0rm: Code: Imports MySql.Data.MySqlClient but it is saying an error in the msgbox.... The snapshot of the error and my sql database snapshot is given below: Error: Database: Please help me why this problem occurs..... Re: How can I read a link from mysql databse??? - Snake_eyes - 03-26-2013 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. Re: How can I read a link from mysql databse??? - mnxford - 03-26-2013 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... Re: How can I read a link from mysql databse??? - brandonio21 - 04-12-2013 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? |