0

I have a function that get 3 argument , a textbox and 2 combobox and use them in the code as temp of a OleDbDataReader but I have a problem and take runtime

error: No value given for one or more required parameters.

 Sub load_txt_code(ByVal nkala As ComboBox, ByVal ckala As ComboBox, ByVal ghyemat As TextBox)

    dr.Close()
    cmd.Connection = con
    cmd.CommandText = "select name_jens from ajnas where id = " & nkala.Text & ""
    dr = cmd.ExecuteReader()

    While dr.Read
        nkala.Text = dr.Item(0)
    End While

    'por kardane combobox e gheymat
    dr.Close()
    cmd.CommandText = "select gheymate_forush from ajnas where id = " & ckala.Text & ""
    dr = cmd.ExecuteReader()

    While dr.Read
        If Not IsDBNull(dr.Item(0)) Then
            ghyemat.Text = dr.Item(0)
        Else
            ghyemat.Text = Nothing
        End If
    End While

End Sub
Jaffer Wilson
  • 7,029
  • 10
  • 62
  • 139
Ravaei
  • 8
  • 6

1 Answers1

0

add a breakpoint in the gheymat.text = dr.item(0) to see if it ever goes there. Your code makes it possible that your text is overwritten if field 0 has a value and field 1 has none. It will read field (1) and then overwrite the text you set wiht dr.item(0) before. So you should add an "end while" behind gheymat.text = dr.item(0) - if your code ever goes there. If this is not enough to tackle it, add an early breakpoint and F10 trough it all, then you can see if your query generates any data in the first place.

mr_w_snipes
  • 171
  • 8