VB.NET - 在这种情况下如何在数据库上保存信息

时间:2015-01-03 21:05:35

标签: database vb.net textbox radio-button picturebox

我正在构建一个使用基于服务的数据库的程序。

我的第一个问题: 我希望当有人点击其中一种颜色时,它会在数据库中存储String,例如" color_red"

第二个问题: 我希望每个单选按钮都存储一个不同的整数

数据库架构:

Database Schema

相关代码:

Public Class Form2

    Private Sub TableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TableBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.TableBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.Database1)

    End Sub

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Database1.Table' table. You can move, or remove it, as needed.
        Me.TableTableAdapter.Fill(Me.Database1.Table)

    End Sub

    Private Sub TableDataGridView_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)

    End Sub

    Private Sub TableBindingNavigator_RefreshItems(sender As Object, e As EventArgs) Handles TableBindingNavigator.RefreshItems

    End Sub

    Private Sub Nb_typeRadioButton_CheckedChanged(sender As Object, e As EventArgs) Handles Nb_typeRadioButton.CheckedChanged

    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click

        PictureBox1.BorderStyle = BorderStyle.Fixed3D
        PictureBox2.BorderStyle = BorderStyle.FixedSingle
        PictureBox3.BorderStyle = BorderStyle.FixedSingle
        PictureBox4.BorderStyle = BorderStyle.FixedSingle
        PictureBox5.BorderStyle = BorderStyle.FixedSingle

    End Sub

    Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click

        PictureBox1.BorderStyle = BorderStyle.FixedSingle
        PictureBox2.BorderStyle = BorderStyle.Fixed3D
        PictureBox3.BorderStyle = BorderStyle.FixedSingle
        PictureBox4.BorderStyle = BorderStyle.FixedSingle
        PictureBox5.BorderStyle = BorderStyle.FixedSingle

    End Sub

    Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles PictureBox3.Click

        PictureBox1.BorderStyle = BorderStyle.FixedSingle
        PictureBox2.BorderStyle = BorderStyle.FixedSingle
        PictureBox3.BorderStyle = BorderStyle.Fixed3D
        PictureBox4.BorderStyle = BorderStyle.FixedSingle
        PictureBox5.BorderStyle = BorderStyle.FixedSingle

    End Sub

    Private Sub PictureBox4_Click(sender As Object, e As EventArgs) Handles PictureBox4.Click

        PictureBox1.BorderStyle = BorderStyle.FixedSingle
        PictureBox2.BorderStyle = BorderStyle.FixedSingle
        PictureBox3.BorderStyle = BorderStyle.FixedSingle
        PictureBox4.BorderStyle = BorderStyle.Fixed3D
        PictureBox5.BorderStyle = BorderStyle.FixedSingle

    End Sub

    Private Sub PictureBox5_Click(sender As Object, e As EventArgs) Handles PictureBox5.Click

        PictureBox1.BorderStyle = BorderStyle.FixedSingle
        PictureBox2.BorderStyle = BorderStyle.FixedSingle
        PictureBox3.BorderStyle = BorderStyle.FixedSingle
        PictureBox4.BorderStyle = BorderStyle.FixedSingle
        PictureBox5.BorderStyle = BorderStyle.Fixed3D

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Try
            Me.Validate()
            Me.TableBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.Database1)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        Try
            Dim db As New Database1TableAdapters.TableTableAdapter
            Dim dbimg As String = db.GetData.Rows(0).Item(1)
            PictureBox1.Image = My.Resources.ResourceManager.GetObject(dbimg)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Me.Close()

    End Sub
End Class

1 个答案:

答案 0 :(得分:-1)

我会在您提供更多质量信息后立即更新我的答案 现在这就是我理解你想要做的事情:

Button.Click事件中你应该写:

If Me.Radiobutton1.Checked = True than
            Value = 1 '' For Example
        Else
            Value = 2 '' For Example
        End If  

或者你可以这样做:

        If Me.Radiobutton1.Checked = True than
            Value = 1
        ElseIf Me.Radiobutton2.Checked = True than
            Value = 2
        End if

这是根据已检查的RadioButton给出值。

关于标记PictureBox我只会添加到Button.Click事件:

        If Me.PictureBox1.BorderStyle = BorderStyle.Fixed3D Then
            StringValue = 1
        ElseIf Me.PictureBox2.BorderStyle = BorderStyle.Fixed3D Then
            StringValue = 2
        ElseIf Me.PictureBox3.BorderStyle = BorderStyle.Fixed3D Then
            StringValue = 3
        ElseIf Me.PictureBox4.BorderStyle = BorderStyle.Fixed3D Then
            StringValue = 4
        ElseIf Me.PictureBox5.BorderStyle = BorderStyle.Fixed3D Then
            StringValue = 5
        End If