Solved

VB.NET MySql Store Procedure

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to send multiple emails at the same time in PHP 12 57
Variable Event ? 3 27
Web Form VB.Net  import CSV 4 36
SQL LINE CONTINUATION ISSUE 12 32
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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