Re: Error using MySqlParameter
Posted by: M Varghese
Date: November 20, 2004 11:29PM

Thankx Chris , It worked.


Public Function AddUser(ByVal fullName As String, ByVal email As String, ByVal password As String) As Integer

' Create Instance of Connection and Command Object
Dim myConnection As New MySqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim sqlText As String
sqlText = "INSERT INTO portal_users ( Name , Password , Email ) VALUES ( ?Name , ?Password , ?Email );select LAST_INSERT_ID() as UserID;"
Dim myCommand As New MySqlCommand(sqlText, myConnection)

' Add Parameters to SPROC
Dim parameterFullName As New MySqlParameter("@Name", MySqlDbType.VarChar, 51, "Name")
parameterFullName.Value = fullName
myCommand.Parameters.Add(parameterFullName)

Dim parameterPassword As New MySqlParameter("@Password", MySqlDbType.VarChar, 50, "Password")
parameterPassword.Value = password
myCommand.Parameters.Add(parameterPassword)

Dim parameterEmail As New MySqlParameter("@Email", MySqlDbType.VarChar, 100, "Email")
parameterEmail.Value = email
myCommand.Parameters.Add(parameterEmail)

Dim UserID As Integer
' Execute the command in a try/catch to catch duplicate username errors
Try
' Open the connection and execute the Command
myConnection.Open()
UserID = myCommand.ExecuteScalar

Catch
' failed to create a new user
Return -1
Finally

' Close the Connection
If myConnection.State = ConnectionState.Open Then
myConnection.Close()
End If
End Try
Return CInt(UserID)
End Function

M Varghese

Options: ReplyQuote


Subject
Written By
Posted
November 20, 2004 01:37AM
November 20, 2004 03:09PM
Re: Error using MySqlParameter
November 20, 2004 11:29PM
November 21, 2004 05:57PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.