2013-05-17 6 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 대신 Quantity를 호출하면 오류가 발생합니다. 예를 들어, 다른 형태로 나는 quantity1 만 채우지 만 그 밖의 양은 채워지지 않습니다. 그러면 데이터를 찾으려 할 때 오류가됩니다.데이터베이스에서 데이터를 가져 오는 중 예외가 발생했습니다.

+1

** 오류는 무엇입니까? ** ** 읽었습니까? – 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 
관련 문제