473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

You have an error in your SQL syntax

Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient

Public Class Form2
Dim MysqlConn As MySqlConnection
Dim sqlconnection As MySqlConnection = New MySqlConnection
Dim serverstring As String = "server=localhost; user id=root; password=; database = project"

Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
Dim sqlstatement As String = "Insert into subject('ID','Code','Description','Unit','Hours') values('" & TextBox5.Text & "','" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
savenames(sqlstatement)
End Sub

Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


sqlconnection.ConnectionString = serverstring

Try
If sqlconnection.State = ConnectionState.Closed Then
sqlconnection.Open()
MsgBox("Successfully connected to mysql database")
Else
sqlconnection.Close()
MsgBox("Connection is closed.")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub savenames(ByRef sqlstatement As String)

Dim cmd As MySqlCommand = New MySqlCommand

With cmd

.CommandText = sqlstatement
.CommandType = CommandType.Text
.Connection = SqlConnection
.ExecuteNonQuery()
End With


SqlConnection.Close()

MsgBox("Successfully Added!")
SqlConnection.Dispose()
End Sub

End Class
Attached Images
File Type: jpg unhandled exception.jpg (58.7 KB, 340 views)
File Type: jpg database.jpg (52.8 KB, 496 views)
Dec 8 '11 #1
2 2237
Rabbit
12,516 Expert Mod 8TB
You don't need quotes around field names.
Dec 8 '11 #2
Ammu
78
Expand|Select|Wrap|Line Numbers
  1. Dim sqlstatement As String = "Insert into subject(ID,Code,Description,Unit,Hours) values('" & TextBox5.Text & "','" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
  2.  
Dec 9 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Balaji | last post by:
I'm trying to do some basic socket programming. here is the line of code which is creating problem.. int FAR PASCAL __declspec (dllexport)(char * addr,int port) Hers is the error I'm...
2
by: kalpana.sinduria | last post by:
Hi all, how to remove the following complle error. When I compiling the code I get the following errors: Compiling... CDrtEachDefFeat.cpp d:\ include\common\cdrtintegfeat.h(39) : error...
0
by: MWK | last post by:
Hi All, I don't understand why I get "error c2061: syntax error : identifier" in VS2003. I thought it's fixed in .Net 2003: __hook(&TCP_Client::LineReceived, client, HandlerLineReceived); ...
1
by: IceColdFire | last post by:
I have a VC++.net Win32 console application, however when I compile , I get this error error C2146: syntax error : missing ';' before identifier 'Length' Explain... Location pointed is ...
1
by: parveen.beniwal | last post by:
hi all i am having the following line of code in my mak file. !IF "$(CFG)" == "" CFG=DesktopCommon - Win32 Release !MESSAGE No configuration specified. Defaulting to DesktopCommon -...
10
by: bobf | last post by:
I am using a program 'My Contact Table' which is a code generator program. It allows you to easily create a PHP/MySQL web application without writing any code. I am trying to create an additional...
6
by: Pixel.to.life | last post by:
So I have this perfectly fine and running app, that uses managed C++ forms. Problem#1: I pass a Bitmap reference to a class, hoping to modify it in one of the class's methods, so it...
6
by: muby | last post by:
Hi everybody :) I'm modifying a C++ code in VC++ 2005 my code snippet void BandwidthAllocationScheduler::insert( Message* msg, BOOL* QueueIsFull,
4
by: srinathvs | last post by:
Hi, I have an access db that I am trying to query from a vb6 program. I've the following code: Dim sSQLQuery As String sSQLQuery = "SELECT * FROM TblData WHERE ID = " & Chr(39) & ID &...
2
shashahayes
by: shashahayes | last post by:
I am getting an error on this line, does anyone have any suggestions? here is the error here is line 25 if area > 750 then charge = 200 1>Furniture.cpp
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.