[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB.NET MySql Store Procedure

Posted on 2008-10-01
3
Medium Priority
?
2,213 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 2000 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

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month18 days, 21 hours left to enroll

834 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