Page 1 of 1

Insert records using VB in Visual Studio .NET 2003

Posted: Thu 05 Jan 2006 11:47
by wrighty
Hi

I'm trying to use VB in VS.NET 2003 to iput data from a PDA to a MySQL database.

Could someone give an example of how to do this please.

Thanks

Posted: Thu 05 Jan 2006 13:20
by Serious
If you use MySQLDirect .NET and want to Insert/Update/Delete rows in database table with Pocket PC you can use the same technicue as in common Windows application.

Some limitations are caused by controls restrictions in .NET Compact Framework. For instance, DataGrid component does not allow data modifications. Use custom dialogs in this case.

Error trying to insert data

Posted: Thu 05 Jan 2006 16:10
by wrighty
I get the following error

An unhandled exception of type 'System.ArgumentException' occurred in CoreLab.MySql.dll

Additional information: ParameterValueMissing

on this line

Dim myConnection As New MySqlConnection(myConnectionString)

myConnectionString isset as
myConnectionString = "Database=mysqldb;Data Source=localhost;User Id=root;Password="

The full code is

Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
' If the connection string is null, use a default.
If myConnectionString = "" Then
myConnectionString = "Database=mysqldb;Data Source=localhost;User Id=root;Password="
End If
Dim myConnection As New MySqlConnection(myConnectionString)
Dim myInsertQuery As String = "INSERT INTO test_table (Name, Telephone, Job) Values('" & TxtName.Text & "', '" & TxtTelephone.Text & "', '" & TxtJob.Text & "')"
Dim myCommand As New MySqlCommand(myInsertQuery)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
Close()
End Sub

Help please

Posted: Thu 05 Jan 2006 16:32
by Serious
You shouldn't use "Password" connection parameter if your MySQL database account has no password.
Valid connection string in this case: "Database=mysqldb;Data Source=localhost;User Id=root;"
Therefore this exception is a bug in MySQLDirect .NET. We'll fix it in the next build.