Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

mysql + VB.Net

Posted on 2003-11-07
6
Medium Priority
?
3,721 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 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…

783 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