VB.NET - 在这种情况下如何在数据库中保存信息
VB.NET - How to save info on database in this case
我正在构建一个使用基于服务的数据库的程序。
我的第一个问题:
我希望当有人点击其中一种颜色时,它会在数据库中存储一个 String
,例如 "color_red"
第二个问题:
我希望每个单选按钮都存储一个不同的整数
数据库架构:
相关代码:
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
一旦您提供更多优质信息,我会尽快更新我的答案。
现在这是我知道你想做的事情:
在 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
我正在构建一个使用基于服务的数据库的程序。
我的第一个问题:
我希望当有人点击其中一种颜色时,它会在数据库中存储一个 String
,例如 "color_red"
第二个问题: 我希望每个单选按钮都存储一个不同的整数
数据库架构:
相关代码:
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
一旦您提供更多优质信息,我会尽快更新我的答案。
现在这是我知道你想做的事情:
在 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