VB.NET - MySQL Error

Asked By Bigboy
10-Feb-12 06:50 AM
I want to search  for a record in MySql database using a name inputed to a textbox, if the record is found, then the record with that name would be outputed to another form's textboxes.
Now I have the following code:

Imports MySql.Data.MySqlClient
Public Class frmSearchResult

    Dim con As MySqlConnection = New MySqlConnection("Datasource=localhost; Database=employee; username=root;")
    Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM employeedetails WHERE Employee Name='" & Trim(frmSearch.txtSearchEmpName.Text) & "'", con)


    Private Sub frmSearchResult_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Try
        Dim c As New MySqlCommand(sql.ToString, con)
        Dim s As MySqlDataReader
        con.Open()
        s = c.ExecuteReader
        While s.Read
          txtEmpNum.Text = Trim(s.GetValue(0))
          txtEmpName.Text = Trim(s.GetValue(1))
          txtDateJoined.Text = Trim(s.GetValue(2))
          txtLeavedays.Text = Trim(s.GetValue(3))
          txtDaysWorked.Text = Trim(s.GetValue(4))
          txtSickDays.Text = Trim(s.GetValue(5))
          txtWorkingDays.Text = Trim(s.GetValue(6))
          txtDaysAllowed.Text = Trim(s.GetValue(7))
          txtNumofLeaveDays.Text = Trim(s.GetValue(8))
        End While
      Catch ex As Exception
        MsgBox(Err.Description)
        con.Close()
      End Try

    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
      Me.Hide()
      frmLeaveDaysCalculator.Show()
      Form4.Hide()
      frmDatabase.Hide()
      frmLogin.Hide()
    End Sub
End Class

Now if I run the program, am receiving the following error:

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
MySQL.Data.MySQLClient.MySQL at line 1

How should I go about this error.

Thank you very much
  Reena Jain replied to Bigboy
10-Feb-12 07:00 AM
hi,

The first thing we need to do is add a reference to the MySql assembly. Click the Project from the menu and then select Add Reference. Under the .Net tab, browse for the MySQL.Data assembly.

Now that the reference has been added, we need to use the Imports directive to import the
MySql.Data.MySqlClient namespace.
  Bigboy replied to Reena Jain
10-Feb-12 07:24 AM
That, I had done already, but the error still comes up
  kalpana aparnathi replied to Bigboy
10-Feb-12 02:27 PM
hi,

About your error please refer this link:http://dev.mysql.com/doc/refman/5.1/en/connector-net-news-5-2-8.html

Thanks,
Create New Account
help
VB.net - MySQL Connection Error I have developed an vb.net application with mysql as database.And it has worked for 2 months.But now when I am logging in the software an error occurs saying "Cant get host name for your address" .The connection string is as below
Parameters MySql and VB.Net .NET Framework Wondering if someone could help me with adding parameters to a mysql query with vb.net Here's my code: mycmd = New MySqlCommand 'mycmd.Parameters.Add("?result", MySqlType.Text) mycmd.Parameters Exception MsgBox(ex.Message) End Try I the exception I get is "You have an error in your sql statement near 'result' What am I doing wrong?? Thanks! Daniel - - - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - -- - - - Posted with NewsLeecher v3.9 Final Web @ http: / / www.newsleecher.com / ?usenet - -- -- -- -- -- -- -- -- -- - -- -- - -- - - - - VB.NET Discussions ParameterDirection.Input (1) ParameterDirection (1) ExecuteNonQuery (1) VB (1) Mycmd.ExecuteNonQuery (1) MySqlCommand
VB.NET and MYSQL situation: i have created one application in vb.net. mysql server is location in another place. so how i can communicate mysql server from vb.net application. anyone know how i can do this thank you very much In your
Problem on Combobox textchange event VB.NET .NET Framework Dear all, I'm new to this VB.NET, my platform using now to do the development is Visual Studio 2008 using the VB.NET 2008 Window Form to create a lorry transportation management system. I'm facing problem with the combobox textchange event now. I'm using MySQL 5.0 with SQLYog v5.29 to develop this system. The following is a form code for the user to insert the Delivery Order document: Imports MySql.Data.MySqlClient Public Class InputDO Public Shared MyConnString As String = "Server = ;Database = logistic_sysdb;Uid = root
Connect VB.NET to PHP .NET Framework Hi, I am not sure if this is the right place for me to post this question. I have a VB.NET program written up for a user-interface, and I wanted to connect this to a as import or connect to the PHP script for me to put in my current VB.NET program? VB.NET Discussions HttpWebRequest (1) WebRequest (1) VB.NET (1) Parser (1) Database (1) Connect (1) MySql