【发布时间】:2017-11-20 15:02:17
【问题描述】:
这是我的代码,我想在一个字段名中输入名字、中间名和姓氏
Try
MysqlConn.Open()
Dim Query As String
Query = "INSERT INTO residentrecords.info (id,last_name,first_name,middle_name,age,address,contact_no,date_of_birth,religion,civil_status,education_attainment,occupation,fathers_name,mothers_name,mothers_occupation,fathers_occupation,gender,purok,blotter,docu,voter) values ('" & add.TextBox_ID.Text & "','" & add.TextBox_LN.Text & "','" & add.TextBox_FN.Text & "','" & add.TextBox_MN.Text & "','" & add.TextBox_Age.Text & "','" & add.TextBox_Address.Text & "','" & add.TextBox_Contact.Text & "','" & add.DateTimePicker1.Text & "','" & add.ComboBox_religion.Text & "','" & add.ComboBox_CS.Text & "','" & add.TextBox_Educ.Text & "','" & add.TextBox_Occu.Text & "','" & add.TextBox1_FathersName.Text & "','" & add.TextBox1_MothersName.Text & "','" & add.TextBox_mothersocc.Text & "','" & add.TextBox_fathersocc.Text & "','" & add.ComboBox_gender.Text & "','" & add.rpurok.Text & "','0','0','" & add.voter.Text & "')"
COMMAND = New MySqlCommand(Query, MysqlConn)
READER = COMMAND.ExecuteReader
MessageBox.Show("Successfully Registered!", "REGISTERED", MessageBoxButtons.OK, MessageBoxIcon.None)
If vbOK = MsgBoxResult.Ok Then
Me.Dispose()
add.Dispose()
add.Enabled = True
residents.Show()
End If
MysqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub
【问题讨论】:
-
您的数据库似乎每个都有列,那么您为什么要连接它们?但是,这不是创建 SQL 的正确方法。使用数据库参数并阅读How to Ask 并获取tour
-
你好 Olivier 谢谢你的回答你能告诉这是什么吗? prnt.sc/hcwlvt
-
这条线
Query = "INSERT INTO residentrecords.info ...是一场噩梦。参数化您的查询并将插入语句分解为 vb 中的多行。如果在 SO 问题中很难看到您的代码,那么在您的 IDE 中一定同样痛苦。 -
感谢大家告诉我更改参数,这就是我所需要的,谢谢
标签: vb.net