Solved

mysql + VB.Net

Posted on 2003-11-07
6
3,712 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

789 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