Insert data to MySQL-Server with assembly MySql.Data ADO.NET

rallez
Member Posts: 4
Hello,
I want to write data to a MySQL-Database with C/AL and assembly MySql.Data.
This code works very fine:
...
ADOMySQLCommand.CommandText := 'INSERT INTO t_ado VALUES(NULL,@PLZ)';
ADOMySQLCommand.Prepare();
ADOMySQLCommand.Parameters.AddWithValue('@PLZ', '99999');
ADOMySQLCommand.ExecuteNonQuery();
...
The code above only creats one new record in the table t_ado.
Next, I want to write new records within a "Repeat - Until" loop.
So I tried this:
...
ADOMySQLCommand.CommandText := 'INSERT INTO t_ado VALUES(NULL,@PLZ)';
ADOMySQLCommand.Prepare();
REPEAT
ADOMySQLCommand.Parameters.AddWithValue('@PLZ', '99999');
--> this is the problem: AddWithValue is the wrong function
--> the right one should be "ADOMySQLCommand.Parameters('@PLZ').Value = 'xxxxx';" like here: https://dev.mysql.com/doc/connector-net/en/connector-net-programming-prepared-preparing.html
ADOMySQLCommand.ExecuteNonQuery();
UNTIL ...
The function .Value isn't available for me. So, whats going wrong? How to fix this?
thx! I'm realiy frustrated
I want to write data to a MySQL-Database with C/AL and assembly MySql.Data.
This code works very fine:
...
ADOMySQLCommand.CommandText := 'INSERT INTO t_ado VALUES(NULL,@PLZ)';
ADOMySQLCommand.Prepare();
ADOMySQLCommand.Parameters.AddWithValue('@PLZ', '99999');
ADOMySQLCommand.ExecuteNonQuery();
...
The code above only creats one new record in the table t_ado.
Next, I want to write new records within a "Repeat - Until" loop.
So I tried this:
...
ADOMySQLCommand.CommandText := 'INSERT INTO t_ado VALUES(NULL,@PLZ)';
ADOMySQLCommand.Prepare();
REPEAT
ADOMySQLCommand.Parameters.AddWithValue('@PLZ', '99999');
--> this is the problem: AddWithValue is the wrong function
--> the right one should be "ADOMySQLCommand.Parameters('@PLZ').Value = 'xxxxx';" like here: https://dev.mysql.com/doc/connector-net/en/connector-net-programming-prepared-preparing.html
ADOMySQLCommand.ExecuteNonQuery();
UNTIL ...
The function .Value isn't available for me. So, whats going wrong? How to fix this?
thx! I'm realiy frustrated
0
Answers
-
No one?0
-
Hello,
I think that you should initialize SQL Command inside loop or change parameter value inside loop instead of adding a new one.
Now it looks like you have initialized the command and inside loop you try to add new parameter each time, but your command has only one parameter. Thus, when you try to add parameter second time you get this error.0 -
Try
ADOMySQLCommand.Parameters.Item('@PLZ').Value
orADOMySQLCommand.Parameters.Item(0).Value
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions