如何在一个字段名中输入3个文本框值

时间:2017-11-20 15:02:17

标签: vb.net

这是我的代码我想在一个Fieldname中输入First_Name,Middle_name和Last_Name

    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

1 个答案:

答案 0 :(得分:0)

在.net中这很容易。你需要在它的空格上拆分一个字符串并单独插入子字符串。

使用像这样的东西

Dim names as String()
Dim firstName as String
Dim middleName as String
Dim lastName as String

names = add.TextBox_Name.Text.Split(" ")

firstName = names(0)
middleName = names(1)
lastName = names(2)

您可以通过正手检查数组长度,以确保用户确实具有中间名称。甚至不止一个。我有两个。只需检查names.length

我希望我没有误解你的问题。这很简短。