473,320 Members | 1,933 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,320 software developers and data experts.

saving data to datagridview

1
i am couldnt able to insert datagrid view manually entered data to mysql db with other control datas together into 1 table.
so i made 2 table and in 1 inserting all grid data in other rest still i m getting the same error:

" you have an error in your SQl syntax; check the manual that coressponds to your mysql server version for right syntax to use near '",",",",")' at line 1"

my code is

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New MySqlConnection
Dim mycommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter

Try
conn.ConnectionString = "server = localhost; database = abc; userid=root; password =root;"
conn.Open()

Catch ex As Exception
MsgBox(ex.ToString)
End Try
Try
Dim Dr As New DataGridViewRow
mycommand.CommandText = "insert into q1 values('" & Lqno.Text & "' , '" & Tqcname.Text & " ',' " & Lqdate.Text & " ', '" & Tqaddress.Text & "','" & Tqsub.Text & "','" & Tsubtotal.Text & "','" & Tvat.Text & "','" & Tgtotal.Text & "')"
mycommand.CommandType = CommandType.Text
mycommand.Connection = conn
myAdapter.SelectCommand = mycommand
mycommand.ExecuteNonQuery()

For Each Dr In Quotdgv.Rows
Try
mycommand.CommandText = "insert into qd values(" & Dr.Cells(0).Value & ",'" & Dr.Cells(1).Value & "','" & Dr.Cells(2).Value & "','" & Dr.Cells(3).Value & "','" & Dr.Cells(4).Value & "','" & Dr.Cells(5).Value & "')"
mycommand.CommandType = CommandType.Text
mycommand.Connection = conn
myAdapter.SelectCommand = mycommand
mycommand.ExecuteNonQuery()
Catch ex As MySqlException
MsgBox(ex.ToString)
End Try
Next


Catch ex As MySqlException
MsgBox(ex.ToString)
End Try



End Sub
Apr 13 '11 #1
1 3309
mshmyob
904 Expert 512MB
I assume q1 and qd are proper table names and also the proper syntax for a SQL INSERT INTO statement is:

INSERT INTO tablename (column list) VALUES (values);

You are missing the column list.

See if that helps.

cheers,
Apr 13 '11 #2

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

Similar topics

0
by: Marc Gravell | last post by:
I have a remote web-method that returns an array of strongly-typed objects; on the client this gets a schema-based representation (as per wsdl.exe). I have an array of (for instance) SearchResult...
1
by: pmclinn | last post by:
I have a formated a structure as follows: <Serializable()>public structure stcOutPut private data as string private visi as string end structure Instances of this strucuture are stored in an...
0
by: RSH | last post by:
Hi, I have created a WinForm that uses a series of dynamic DDLs to select Databases/tables and then loads the data into a DataGridView. The 2.0 Datagridview allows users to reorder columns etc...
1
by: Magnus | last post by:
I'm testing walkthrough saving data to a Database (Multiple Tables). http://msdn2.microsoft.com/en-us/library/4esb49b4(VS.80).aspx In the famous Customer/Order example, I'm getting referential...
4
by: sharper | last post by:
Hi to all ! I have problem with C# and access databasses! I can't to insert new record in database , ( I mean I made grid view and connect him with a access database and made all things to...
0
by: =?Utf-8?B?QkFUT04=?= | last post by:
I have realy big problem I try lot of things but never success! I need a HELP! Problem is in that I made database in Microsoft access and connect her to C# form and datagridview. and it...
2
by: Omar Abid | last post by:
Hi, I'm using the following code to open a data base and show it's content in a Data Grid View ---- Code ----- Imports System.Data.SqlClient Private Sub Form1_Load(ByVal sender As...
0
by: enrico via DotNetMonster.com | last post by:
how do i save fields that were entered in a datagridview? -- Message posted via DotNetMonster.com http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-vb-net/200803/1
4
by: Meddix | last post by:
Hi Everyone, I am new to C#, kind of new to programming altogether. It is something I am really enjoy learning but I am a little stuck with hierarchical updates. I am using Visual Studio 2008...
5
by: AiVrea | last post by:
Hi, I have 2 access tables (table1, table2), table2 is related to the field "Nr Crt"(which is an AutoNumber) in table1 in a "one-to-many" relation. Table1 is connected to the vb form to textboxes,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.