Hello,
I want to know how to insert values into a mysql data base from a text box, and how to read from the data base and show it in labels.
I'm developiing for windows mobile using vb2005, mysql and devart dot net connect for mobile.
The code i have to add data is the following:
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
If txt_ward.Text = "" Then
MsgBox("Please insert ward name.", MsgBoxStyle.Information, "Mobile Audit'09")
End If
Dim ward As String
ward = txt_ward.Text
MySqlConnection1.Open()
MySqlCommand1.ExecuteNonQuery()
Try
Catch exception As Devart.Data.MySql.MySqlException
MsgBox(exception.Message)
End Try
MySqlConnection1.close()
End Sub
The command text i have in the MySqlCommand1:
INSERT INTO audit (Auditor_id,Audit_date,Audit_Ward) VALUES (1,2009-06-04, txt_ward.text)
Any help ?
Thanks
Insert from text box/query and show in labels.
-
- Posts: 3
- Joined: Fri 05 Jun 2009 16:58
-
- Posts: 3
- Joined: Fri 05 Jun 2009 16:58
Please use the parameters collection of the MySqlCommand object to assign the value from txt_ward.text to your query. For example:
Please notify us about the results.
Code: Select all
Dim MySqlCommand1 As MySqlCommand = MySqlConnection1.CreateCommand()
MySqlCommand1.CommandText = "INSERT INTO audit (Auditor_id,Audit_date,Audit_Ward) VALUES (1,2009-06-04, :param1)"
Dim param1 As New MySqlParameter()
param1.ParameterName = "param1"
param1.Direction = Data.ParameterDirection.Input
param1.MySqlType = MySqlType.Text
param1.Value = txt_ward.text
MySqlCommand1.Parameters.Add(param1)
MySqlCommand1.ExecuteNonQuery()
-
- Posts: 3
- Joined: Fri 05 Jun 2009 16:58
Code: Select all
Dim MySqlCommand1 As MySqlCommand = MySqlConnection1.CreateCommand()
MySqlCommand1.CommandText = "SELECT * FROM audit WHERE Auditor_id=:param1"
Dim param1 As New MySqlParameter()
param1.ParameterName = "param1"
param1.Direction = Data.ParameterDirection.Input
param1.MySqlType = MySqlType.Int
param1.Value = 10 //any value
MySqlCommand1.Parameters.Add(param1)
Dim MySqlDataReader As reader = MySqlCommand1.ExecuteReader()
While (reader.Read())
lblId.Text = reader[0].ToString()
lblDate.Text = reader[1].ToString()
lblWard.Text = reader[2].ToString()
End While