Solved

VB.NET MySql Store Procedure

Posted on 2008-10-01
3
2,181 Views
Last Modified: 2008-10-06
It is my first time having to call a mysql store procedure from vb.net. I am trying to use the below code but it keeps saying

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SP_Validate_user' at line 1

What am i doing wrong? The store procedure does not show any problems. It commited successful
Imports MySql.Data
Imports MySql.Data.MySqlClient
 
    Public Shared Function validate_user_credentials(ByVal username As String, ByVal password As String) As Boolean
        Dim myConnection As New MySqlConnection
        myConnection = New MySqlConnection(myConnectionString)
        Dim myCommand As New MySqlCommand("SP_Validate_user")
        myCommand.Connection = myConnection
        myConnection.Open()
 
        myCommand.Parameters.AddWithValue("Username", username)
        myCommand.Parameters.AddWithValue("UPassword", password)
 
        Dim sqlReader As MySql.Data.MySqlClient.MySqlDataReader = myCommand.ExecuteReader
        While sqlReader.Read()
            MsgBox(sqlReader(0))
            MsgBox(sqlReader(1))
        End While
        myCommand.Connection.Close()
 
        sqlReader = Nothing
    End Function

Open in new window

0
Comment
Question by:jimseiwert
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
rionroc earned 500 total points
ID: 22621351
Hello

Check this out:

Imports MySql.Data
Imports MySql.Data.MySqlClient

Public Class Form1


    Protected Const myConnectionString As String = "server=" & "localhost" & ";" _
                & "port=" & "3306" & ";" _
                & "user id=" & "root" & ";" _
                & "password=" & "" & ";" _
                & "database=TESTONLY_CHANGE_IT"


Public Shared Function validate_user_credentials(ByVal username As String, ByVal password As String) As Boolean
        Dim myConnection As New MySqlConnection
        myConnection = New MySqlConnection(myConnectionString)
        Dim myCommand As New MySqlCommand("SP_Validate_user")
        myCommand.Connection = myConnection

       
        '''''//////ADDED :)

        '''''//////ADDED :)
        myCommand.CommandType = CommandType.StoredProcedure


        myConnection.Open()
        myCommand.Parameters.AddWithValue("Username", username)
        myCommand.Parameters.AddWithValue("UPassword", password)

        Dim sqlReader As MySql.Data.MySqlClient.MySqlDataReader = myCommand.ExecuteReader
        While sqlReader.Read()
            MsgBox(sqlReader(0))
            MsgBox(sqlReader(1))
        End While
        myCommand.Connection.Close()

        sqlReader = Nothing
    End Function
   


End Class


Great is our GOD.
:)
0
 
LVL 12

Expert Comment

by:rionroc
ID: 22621362
If you want to learn more, please visit:
http://www.vbmysql.com/articles/vbnet-mysql-tutorials/the-vbnet-mysql-tutorial-part-1


Great is our GOD.
:)
0
 

Expert Comment

by:klay8
ID: 22631322
try this
Dim myConnection As New MySqlConnection
        myConnection = New MySqlConnection(myConnectionString)

    Dim myCommand As New MySqlCommand(" Call SP_Validate_user('&username&"','"&password"')"
myCommand.CommandType = CommandType.StoredProcedure;      
  myCommand.Connection = myConnection
        myConnection.Open()
 
       
 

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Creating and Managing Databases with phpMyAdmin in cPanel.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question