Solved

VB.NET MySql Store Procedure

Posted on 2008-10-01
3
2,163 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now