Connection string for mysql database and how to write stored procedure in mysql database and use it
To write a stored procedure for login page in MySql database and use that in windows login form.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
GAUTAM RAPARTHIPosted Jul 6, 2011, 8:13 AM
When i am trying to execute the procedue in MySql ,its getting error.So,please provide the solution of how to do it by using MySql database as soon as possible.
Rohatash KumarPosted Jul 6, 2011, 1:26 AM
creating a table in SQL server database which has the username, password and email fields. Table looks like this.
create table registrationtab
(
Username varchar(100),
Email varchar(100),
Password varchar(20)
)
Step-2
Create stored procedure
Now Creating stored procedure for login. That means values will be match in table using stored procedure. Stored procedure looks like that for it.
create PROCEDURE CheckUser
(
@username as varchar(50),
@password as varchar(50)
)
AS
SELECT* FROM registrationtab WHERE username=@username AND password=@password
Now creating a window form with the username and password field which are defined in the table. And write following code in login button event.
Dim strcon As String = "Data Source=.;uid=sa;pwd=Password$2;database=master"
Dim con As New SqlConnection(strcon)
Dim com As New SqlCommand("CheckUser", con)
com.CommandType = CommandType.StoredProcedure
Dim p1 As New SqlParameter("username", TextBoxusername.Text)
Dim p2 As New SqlParameter("password", TextBoxpassword.Text)
com.Parameters.Add(p1)
com.Parameters.Add(p2)
con.Open()
Dim rd As SqlDataReader = com.ExecuteReader()
If rd.HasRows Then
rd.Read()
Labelinfo.Text = "Login successful."
Else
Labelinfo.Text = "Invalid username or password."
End If