Solved

mysql + VB.Net

Posted on 2003-11-07
6
3,717 Views
Last Modified: 2007-12-19
Hi there,

I've recently converted an Access database to a mysql database, and all of my UPDATE, INSERT and DELETE queries have broken.  The following is an example of the update code that I'm using.  Can anybody tell me where I've gone wrong in my syntax?

(...connection code...)

Dim com As OdbcCommand

Dim UpdateCom As String = "UPDATE " & lblGrid.Text & " SET A = @A, B = @B, " _
             & "C = @C, D = @D, E = @E, F = @F, G = @G, H = @H, I = @I WHERE A = @A"

        com = New OdbcCommand(UpdateCom, con)

        com.Parameters.Add(New OdbcParameter("@A", OdbcType.BigInt, 12))
        com.Parameters.Add(New OdbcParameter("@B", OdbcType.VarChar, 15))
        com.Parameters.Add(New OdbcParameter("@C", OdbcType.VarChar, 17))
        com.Parameters.Add(New OdbcParameter("@D", OdbcType.VarChar, 6))
        com.Parameters.Add(New OdbcParameter("@E", OdbcType.VarChar, 20))
        com.Parameters.Add(New OdbcParameter("@F", OdbcType.VarChar, 30))
        com.Parameters.Add(New OdbcParameter("@G", OdbcType.Text, 300))
        com.Parameters.Add(New OdbcParameter("@H", OdbcType.DateTime, 8))
        com.Parameters.Add(New OdbcParameter("@I", OdbcType.VarChar, 36))
        com.Parameters("@A").Value = dgDisplay.DataKeys(CInt(e.Item.ItemIndex))
        com.Parameters("@H").Value = Server.HtmlEncode(DateTime.Now.ToString())
        com.Parameters("@I").Value = Context.User.Identity.Name.ToString()

(...the other values are taken from text boxes created in the datagrid while in edit mode...)

(...error checking code...)

com.ExecuteNonQuery()

Thanks in advance!

0
Comment
Question by:Headspace
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 17

Expert Comment

by:Squeebee
ID: 9704410
How about showing the final query and error message MySQL produced?
0
 
LVL 9

Author Comment

by:Headspace
ID: 9704967
...the UPDATE command doesn't produce an error, it simply doesn't update; the same goes for the DELETE statement.  The INSERT statement produces the error "...Column 'A' cannot be null at Microsoft.Data.Odbc.OdbcConnection...line 298", where line 298 = com.ExecuteNonQuery().  Basically, it seems that none of the fields that are used to assign data to a parameter are recognized. I had hoped that someone familiar with VB.Net and mysql would immediately see the flaws in my code that would create an error, as the error messages (or lack thereof) don't seem to tell much.
0
 
LVL 17

Accepted Solution

by:
Squeebee earned 125 total points
ID: 9704984
Well, I know VB6 and MySQL, so while I am sorry I have no instant answers I may be able to help work through this.

1) What version of MySQL are you using?
2) What are you using for a driver? MyODBC or one of the new .NET specific projects?

Note that I am not sure any of the drivers currently support Prepared statements except maybe the very latest MyODBC (3.52) and very maybe the byteFX driver.
0
Upcoming Webinar: Percona XtraDB Cluster 6/21 10am

Join Percona’s MySQL Practice Manager Kenny Gryp and QA Engineer, Ramesh Sivaraman as they present Percona XtraDB Cluster, Galera Cluster, MySQL Group Replication on Wednesday, June 21, 2017 at 10:00 am PDT / 1:00 pm EDT (UTC-7).

 
LVL 9

Author Comment

by:Headspace
ID: 9718697
I'm using MySQL version 4.0.16, and version 3.51 of the MyODBC driver.  Your response prompted me to beat my head against the wall for several hours today trying the 2.50 and 3.52 MyODBC drivers, the byteFX driver, and a custom .NET data provider from eInfo Designs, none of which were successful in the various combinations tested.  I was unable to successfully build the 3.52 driver on my WinXP machine, however, so I'll try again on Wednesday.

Thanks a bunch for the push, squeebee!
0
 
LVL 9

Author Comment

by:Headspace
ID: 9750135
OK...I still can't get the 3.52 driver to build, but I found a way around the insert statement using a different syntax:

Dim InsertCmd As String = "INSERT INTO " & lblGrid.Text & " (A, B, C, D, E, F, G, H, I, J) VALUES "
InsertCmd &= "('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}')"

values.Add(Server.HtmlEncode(txtA.text))
values.Add(Server.HtmlEncode(txtB.Text))
etc...

sql = String.Format(InsertCmd.ToString(), values.ToArray())

(...error checking code...)

com.ExecuteNonQuery()

Now I have to figure out how to do this when the fields aren't created yet.  I'm going to close this one out, since you helped get me going.  

Thanks Again...
0
 
LVL 17

Expert Comment

by:Squeebee
ID: 9750194
Glad I could help at least a bit.

Regards,
Mike Hillyer
www.vbmysql.com
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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