2015-01-03 82 views
-2

我正在构建一个使用基于服务的数据库的程序。VB.NET - 如何在这种情况下保存数据库信息

我的第一个问题: 我想,当有人点击其中一种颜色将一个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 
+0

你尝试编写任何代码,并告诉我们你的进展如何? –

+0

问题是你没有显示任何企图在你身上这样做。 – OneFineDay

+0

我的数据库的一张图片: http://srv1.jpg.co.il/4/54a859e4bf576.jpg 我厌倦了很多事情,但没有什么可能有助于理解。 – WoeIsMe

回答

-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 
+0

谢谢,这正是我所要求的,但现在我的问题是如何将这些信息存储在数据库中? – WoeIsMe

+0

我很抱歉,但这是完全不同的问题。你应该为此提出一个新问题。但我建议你查看堆栈上的答案,因为你会发现100%的答案。另外,如果我的问题帮助您解决了您的问题,请投票并将其作为答案进行检查。最好的问候,可敬 – Hoh