Solved

mysql + VB.Net

Posted on 2003-11-07
6
3,707 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now