Results 1 to 12 of 12

Thread: [2008] Need help adding content from textbox to mysql database

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    79

    [2008] Need help adding content from textbox to mysql database

    Hello, im working on an application that allows you to create a login. It's suppose to add the content from textbox 1 as your username, the content from textbox 2 as your password.
    So far this is what i got

    Code:
    Imports System.Data.SqlClient
    Public Class Form1
        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim ra As Integer
        'integer holds the number of records inserted 
        Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles MyBase.Load
        End Sub
    
        Public Function RandomNumber(ByVal MaxNumber As Integer, _
        Optional ByVal MinNumber As Integer = 0) As Integer
            Dim r As New Random(System.DateTime.Now.Millisecond)
            If MinNumber > MaxNumber Then
                Dim t As Integer = MinNumber
                MinNumber = MaxNumber
                MaxNumber = t
            End If
    
            Return r.Next(MinNumber, MaxNumber)
    
        End Function
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Accountname As String
            Dim Password As String
            Dim Accountdetails As String
    
            Accountname = Accname.Text
            Password = Pwd.Text
            Accountdetails = " Accountname: " & Accountname & " Password: " & Password
    
            MsgBox("Please wait a moment")
            myConnection = New SqlConnection("server=localhost;uid=root;pwd=xxxxxx;database=logon")
            myConnection.Open()
            myCommand = New SqlCommand("Insert into Accounts values 7," & Accountname & "," & Password & ",0,0,null,null,null,8")
            ra = myCommand.ExecuteNonQuery()
            'MsgBox("New Row Inserted" & ra)
            myConnection.Close()
            MsgBox("Your account has been created your details is as following:" & Accountdetails)
        End Sub
    End Class
    Also at "insert into accounts values 7," i would like the 7 to be an random number (because its suppose to work with more than one entry.)
    How would i go about getting this to actually connect to the database? and make the 7 be an random generated number, ive been googling for ages, i simply cant find what im looking for.

    All help will be very appreciated,

    Sincerely
    Kolklik

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: [2008] Need help adding content from textbox to mysql database

    Do you have the MySQL .NET Connector installed?
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    79

    Re: [2008] Need help adding content from textbox to mysql database

    nope, do i need too? Btw, this program is suppose to connect to an remote sql database, if that makes any diffrence

  4. #4
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: [2008] Need help adding content from textbox to mysql database

    Err... are you connecting to a Microsoft SQL Database or a MySQL Database or both?
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    79

    Re: [2008] Need help adding content from textbox to mysql database

    an mysql, mysql 5.0

  6. #6
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: [2008] Need help adding content from textbox to mysql database

    Ok, then you'll need the connector. Head over to MySQL's site, or just do a quick Google search for "MySQL .NET Connector". Get the version 5.2.1, it's the newest and it integrates into Visual Studio 2008.

    When it's installed and you restart Visual Studio, add the reference "Mysql.Data" into your project. You'll then have the Mysql namespace which has the MySqlConnection, MySqlCommand, MySqlDataAdapter, etc...

    Also, you don't need, nor want the System.Data.SqlClient or any of it's objects, since that is ONLY for Microsoft SQL Server, and not MySQL.

    (You'd think these big companies would have more creative names for their database systems to set them apart...)
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    79

    Re: [2008] Need help adding content from textbox to mysql database

    hehe, thank you very much jenner +rep for sure!

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    79

    Re: [2008] Need help adding content from textbox to mysql database

    nvm this post fixed
    Last edited by kolklik; Mar 26th, 2008 at 02:39 PM.

  9. #9
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: [2008] Need help adding content from textbox to mysql database

    Thanks much! The MySQL provider works just like any other database provider if you're used to working with them. Should do everything you need it to. I understand the v6.0 code they're working on supports LINQ as well.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    79

    Re: [2008] Need help adding content from textbox to mysql database

    my mysql is running on port 3308, how can i embed that in the connectionstring, do i even need to?


    Dim MySQLConnectionString As String

    MySQLConnectionString = "Server=localhost;" & _
    "Database=myDatabase;" & _
    "Uid=myUserID;" & _
    "Pwd=myPassword;" & _
    "Connect Timeout=30;"

  11. #11
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: [2008] Need help adding content from textbox to mysql database

    Try that. I like String.Format() It's a little used trick and works very much like C's sprintf() function.

    Code:
            Dim mCon As New MySqlConnection
    
            mCon.ConnectionString = String.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};", _
                                    strServer, _
                                    intPort, _
                                    strDatabase, _
                                    strUser, _
                                    strPassword)
            mCon.Open()
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  12. #12
    Addicted Member
    Join Date
    Dec 2006
    Posts
    207

    Re: [2008] Need help adding content from textbox to mysql database

    I have attached a MySQL.Data.dll file.

    Place this file into the Bin folder where your application is. something.exe

    To begin using this you will need to add a reference to it.

    Commands are as such.
    Code:
        Dim dbConnection As New MySql.Data.MySqlClient.MySqlConnection
        Dim dbCommand As New MySql.Data.MySqlClient.MySqlCommand
        Dim dbReader As MySql.Data.MySqlClient.MySqlDataReader
        Dim dbAdapt As New MySql.Data.MySqlClient.MySqlDataAdapter
    
            dbConnection.ConnectionString = "Server='192.168.1.X'; Database='XXX'; Port=XXXX; Uid='XXXX'; Password='XXXX';"
            dbConnection.Open()
    The commands are much like the Oledb.
    Attached Files Attached Files

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