Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mysql + VB.Net

Posted on 2003-11-07
6
Medium Priority
?
3,719 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 500 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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

721 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