2013-05-17 57 views
1
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click 
     Dim data As DataRow 

     Try 
      OleDbDataAdapter1.Fill(Me.DataSet11.PAYMENT) 
      data = DataSet11.PAYMENT.Rows.Find(txtpayment.Text) 
      txtpayment.Text = data("CustomerIC") 
      txtName.Text = data("CustomerName") 
      txtadd.Text = data("CustomerAddress") 
      txttel.Text = data("NoTel") 
      If cKurung.AutoCheck = True Then 
       cKurung.Checked = data("Baju Kurung") 
       Quan1 = Convert.ToInt32(txtQ1.Text) 
       Quan1 = data("Quantity1") 
      End If 

      If cKebaya.AutoCheck = True Then 
       cKebaya.Checked = data("Baju Kebaya") 
       Quan2 = Convert.ToInt32(txtQ2.Text) 
       Quan2 = data("Quantity2") 
      End If 

      If cTudung.AutoCheck = True Then 
       cTudung.Checked = data("Tudung") 
       Quan3 = Convert.ToInt32(txtQ3.Text) 
       Quan3 = data("Quantity3") 
      End If 

      If cSelendang.AutoCheck = True Then 
       cSelendang.Checked = data("Selendang") 
       Quan4 = Convert.ToInt32(txtQ4.Text) 
       Quan4 = data("Quantity4") 
      End If 

      If cTelekung.AutoCheck = True Then 
       cTelekung.Checked = data("Telekung") 
       Quan5 = Convert.ToInt32(txtQ5.Text) 
       Quan5 = data("Quantity5") 
      End If 

      If cAnakTudung.AutoCheck = True Then 
       cAnakTudung.Checked = data("Anak Tudung") 
       Quan6 = Convert.ToInt32(txtQ6.Text) 
       Quan6 = data("Quantity6") 
      End If 
      txtQuan.Text = data("Quantity") 
      txtPrice.Text = data("Price") 

     Catch ex As Exception 
      MessageBox.Show("Invalid Customer IC", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
      txtpayment.Text = "" 
      txtpayment.Focus() 
      txtpayment.ReadOnly = False 

     End Try 
    End Sub 

獲取數據這是我的代碼。調用數量而不是Quantity1它會拋出錯誤。例如,在其他形式中,我僅填充數量1,但其他數量我不填充,然後當我想查找數據時,它將會出錯。異常從數據庫

+1

**錯誤是什麼_say _?**您是否閱讀過? – SLaks

+0

** txtQ1.AutoCompleteCustomSource = data(「Quantity1」)**部分發生錯誤? – matzone

+0

@SLaks會這樣說:「輸入字符串格式不正確。」 – user2387931

回答

1

我覺得你的問題在於,包含Convert.ToInt32(txtQ.Text)那些線,其中你想一個可能是無效的字符串轉換爲整數的一個。考慮使用Int32.TryParse,而不需要處理例外:

Dim result As Int32; 

' Returns true if conversion was successful 
If Int32.TryParse(txtQ1.Text, out result) Then 
     Quan1 = result; 
End If