[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.
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...)
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.
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()