Results 1 to 10 of 10

Thread: [RESOLVED] MySQL Help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    340

    Resolved [RESOLVED] MySQL Help

    Code:
    Dim SQLQuery = "SELECT * FROM MYTABLE WHERE MYCOLUMD = '" + TextBox1.Text + "'"
    Instead of a textbox, how can I do this:

    Code:
    FFF.DownloadString("http://www.mywebsite.com")

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    340

    Re: MySQL Help

    Anyone?

  3. #3
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: MySQL Help

    First off, use a parameterised query to guard against SQL injection attacks. Like this:
    vbnet Code:
    1. Dim sqlQuery As New SqlCommand("SELECT * FROM MYTABLE WHERE MYCOLUMD = @columd")
    2. sqlQuery.Parameters.AddWithValue("columd", TextBox1.Text)

    As to your question, I assume FFF is an instance of WebClient? In which case, DownloadString() returns
    a string containing the entire resource. You may need to parse out the value you're after from the return from this function. Maybe not though. Once you've got the string that represents your value, you simply use that in place of the 'TextBox1.Text' expression.


    [Edit: for MySQL, you'd be using the MySQL client library, no doubt. So use MySqlCommand instead of SqlCommand. I am pretty sure that the parameter syntax in the query is the same (i.e. named parameters preceeded with an '@' symbol]

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    340

    Re: MySQL Help

    Code:
    Dim FFF As New System.Net.WebClient()
            Dim SQLQuery = "SELECT * FROM TABLE WHERE COLUMD =   FFF.DownloadString("http://www.mywebsite.org")
    That is my current code. I'm not too worried about SQL injection hacks at the moment, because this is just for my personal use.

    The problem with the above code though is error "End of statement expected" and "SQLQuery is not declared. It may be in accessible..."

    Can you post example code?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    340

    Re: MySQL Help

    Also, I didn't want to make another thread, but I have another error.

    Code:
    Private Sub CheckBox1_CheckChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
    
    If TextBox1.Text = "Default" Then
                MessageBox.Show("Default")
                CheckBox1.Checked = False
            Else
    MsgBox("Not Default")
    End If
    End Sub
    Whenever the textbox says "Default" and I click on the checkbox, the msgbox pops up twice. Any way to fix this?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MySQL Help

    Quote Originally Posted by Ritzky View Post
    Also, I didn't want to make another thread, but I have another error.
    So are you going to post every error you ever have for the rest of your life to this thread? One thread per topic and one topic per thread please. New topic = new thread.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    340

    Re: MySQL Help

    Ok well how about the answer to the first question?

  8. #8
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: MySQL Help

    Quote Originally Posted by Evil_Giraffe View Post
    As to your question, I assume FFF is an instance of WebClient? In which case, DownloadString() returns
    a string containing the entire resource. You may need to parse out the value you're after from the return from this function. Maybe not though. Once you've got the string that represents your value, you simply use that in place of the 'TextBox1.Text' expression.
    So assuming you just want the returned string from that DownloadString method in place of the TextBox's Text, you started with this:

    Code:
    Dim SQLQuery = "SELECT * FROM TABLE WHERE COLUMD = '" + TextBox1.Text + "'"
    and, replacing the "TextBox1.Text" expression with "FFF.DownloadString("...")" as I suggested, you ended up with this:

    Code:
    Dim SQLQuery = "SELECT * FROM TABLE WHERE COLUMD = FFF.DownloadString("http://www.mywebsite.org")
    (Hint: where have the red bits gone?)

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MySQL Help

    Quote Originally Posted by Ritzky View Post
    Ok well how about the answer to the first question?
    That's a good reason not to bring up new topics in existing threads. I assumed that the original question had been answered. Now that I look at it, I don't even really know what the question is. Are you saying that you want to get some text from a web site and then use that text in a SQL query? You might try providing a FULL and CLEAR explanation in future because those with no prior experience with your project, i.e. everyone but you, won't necessarily be able to interpret code snippets. Anyway, if that's what you want then you pretty much do exactly what you said. You use the result of DownloadString instead of the Text of the TextBox. This is your original code:
    Code:
    Dim SQLQuery = "SELECT * FROM MYTABLE WHERE MYCOLUMD = '" + TextBox1.Text + "'"
    This would be your new code:
    Code:
    Dim SQLQuery = "SELECT * FROM MYTABLE WHERE MYCOLUMD = '" + FFF.DownloadString("http://www.mywebsite.com") + "'"
    It's just a straight substitution of one String for another.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    340

    Re: MySQL Help

    i tried that but it didn't work.

    Code:
    Dim SQLQuery = "SELECT * FROM TABLE WHERE COLUMN = '" & FFF.DownloadString("yourwebsite.com") & "'"
    This worked though.

    thanks for all the helpp!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width