2015-01-03 137 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