Listbox to textboxes
-
I am trying to when I click on a name in linkbox1 to show all the data in access database table in my texboxes. But it gives me this error "No value given for one or more required parameters" Here are my Code. Don't know why it is not working Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Dim SqlStr As String SqlStr = "Select * from tblokkies where luidraad = " & ListBox1.Items(ListBox1.SelectedIndex) FillTextBox(SqlStr) End Sub Public Function FillTextBox(ByVal Sqlstring As String) Dim OleDbConn As OleDbConnection = New OleDbConnection(ConnString) OleDbConn.Open() Dim MyDataReader As OleDbDataReader Dim MyOleDbCommand As OleDbCommand = New OleDbCommand() MyOleDbCommand.Connection = (OleDbConn) MyOleDbCommand.CommandText = Sqlstring MyDataReader = MyOleDbCommand.ExecuteReader Try Do While MyDataReader.Read TxtLuidraad.Text = (MyDataReader.Item(1)) txtA1.Text = (MyDataReader.Item(2)) txtA2.Text = (MyDataReader.Item(3)) txtA3.Text = (MyDataReader.Item(4)) txtA4.Text = (MyDataReader.Item(5)) txtA5.Text = (MyDataReader.Item(6)) txtA6.Text = (MyDataReader.Item(7)) txtA7.Text = (MyDataReader.Item(8)) txtA8.Text = (MyDataReader.Item(9)) txtA9.Text = (MyDataReader.Item(10)) txtA10.Text = (MyDataReader.Item(11)) Loop Catch err As System.Exception MyDataReader.Close() OleDbConn.Close() OleDbConn.Dispose() End Try End Function
-
I am trying to when I click on a name in linkbox1 to show all the data in access database table in my texboxes. But it gives me this error "No value given for one or more required parameters" Here are my Code. Don't know why it is not working Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Dim SqlStr As String SqlStr = "Select * from tblokkies where luidraad = " & ListBox1.Items(ListBox1.SelectedIndex) FillTextBox(SqlStr) End Sub Public Function FillTextBox(ByVal Sqlstring As String) Dim OleDbConn As OleDbConnection = New OleDbConnection(ConnString) OleDbConn.Open() Dim MyDataReader As OleDbDataReader Dim MyOleDbCommand As OleDbCommand = New OleDbCommand() MyOleDbCommand.Connection = (OleDbConn) MyOleDbCommand.CommandText = Sqlstring MyDataReader = MyOleDbCommand.ExecuteReader Try Do While MyDataReader.Read TxtLuidraad.Text = (MyDataReader.Item(1)) txtA1.Text = (MyDataReader.Item(2)) txtA2.Text = (MyDataReader.Item(3)) txtA3.Text = (MyDataReader.Item(4)) txtA4.Text = (MyDataReader.Item(5)) txtA5.Text = (MyDataReader.Item(6)) txtA6.Text = (MyDataReader.Item(7)) txtA7.Text = (MyDataReader.Item(8)) txtA8.Text = (MyDataReader.Item(9)) txtA9.Text = (MyDataReader.Item(10)) txtA10.Text = (MyDataReader.Item(11)) Loop Catch err As System.Exception MyDataReader.Close() OleDbConn.Close() OleDbConn.Dispose() End Try End Function
Wow, is your code ever illegible. Is this deliberate ? What type is luidraad ? Should the item be in quotes ? What line is blowing up ? Have you stepped through the code to see if the returned data has that many items in it ? Does VB really index by 1 instead of by 0 ? I guess it would.
Christian Graus Driven to the arms of OSX by Vista.
-
Wow, is your code ever illegible. Is this deliberate ? What type is luidraad ? Should the item be in quotes ? What line is blowing up ? Have you stepped through the code to see if the returned data has that many items in it ? Does VB really index by 1 instead of by 0 ? I guess it would.
Christian Graus Driven to the arms of OSX by Vista.
Sorry my engilsh is not so good, what do you mean by illegble and deliberate. Is there onther way do this this codeing. Luidraad type = text (150) No quotes Can not see waht line is blowing up. Did step true here is what I get when I press F8. 1. Click on 4th entry in listbox1 (Hendrik) 2. Dim Sqlstr as string (Sqlstr Nothing) 3. After F8 = Dim Sqlstr as string (Sqlstr "Select *from tblokkies where luidraad=Hendrik") 4. listbox1.items(listbox1.selectedindex) (Listbox1.items {System.Windows.forms.listbox.objectcollection) 5 After F8 = listbox1.items(listbox1.selectedindex) (Listbox1.selectedindex 4) 6. Filltextbox(Sqlstr) (Filltextbox Nothing) 7. Dim Oledbconn as oledbconnection = new oledbconnection(Connstring) (OleDbConn {system.data.oleDbConnection} (ConnectionString "Provider=microsoft.jet.oledb.4.0;data source=c:\blokkies\blokkies.mdb" (ConnectionTimeout 15 (Conteiner nothing (Database "" (DataSource "c:\blokkies\blokkies.mdb" (Provider "Microsoft.jet.oledb.4.0" (Serverversion {"invalid operation. The connection is closed"} (Site Nothing (State Closed {0} 8. dim myoledbcommand nothing dbconn 9. after F8 (Myoledbcommand {system.data.oledb.oledbcommand} (commandtext "" (Commandtimeout 30 (commandtype text {1} (connection nothing (container nothing (designtimevisible true (parameters {system.data.oledb.oleparametercollection} (Site nothing (transaction nothing (updatedrowsource both {3} 10. myoledbcommand.connection = (oledbconn) (OleDbConn {system.data.oleDbConnection} (ConnectionString "Provider=microsoft.jet.oledb.4.0;data source=c:\blokkies\blokkies.mdb" (ConnectionTimeout 15 (Conteiner nothing (Database "" (DataSource "c:\blokkies\blokkies.mdb" (Provider "Microsoft.jet.oledb.4.0" (Serverversion "04.00.0000" (Site Nothing (State open {1} 11. myoledbcommand.commandtext =sqlstring = myoledbcommand.commandtext "" 12. After F8 =sqlstring = "select*from tblokkies where luidraad=Hendrik"
-
Sorry my engilsh is not so good, what do you mean by illegble and deliberate. Is there onther way do this this codeing. Luidraad type = text (150) No quotes Can not see waht line is blowing up. Did step true here is what I get when I press F8. 1. Click on 4th entry in listbox1 (Hendrik) 2. Dim Sqlstr as string (Sqlstr Nothing) 3. After F8 = Dim Sqlstr as string (Sqlstr "Select *from tblokkies where luidraad=Hendrik") 4. listbox1.items(listbox1.selectedindex) (Listbox1.items {System.Windows.forms.listbox.objectcollection) 5 After F8 = listbox1.items(listbox1.selectedindex) (Listbox1.selectedindex 4) 6. Filltextbox(Sqlstr) (Filltextbox Nothing) 7. Dim Oledbconn as oledbconnection = new oledbconnection(Connstring) (OleDbConn {system.data.oleDbConnection} (ConnectionString "Provider=microsoft.jet.oledb.4.0;data source=c:\blokkies\blokkies.mdb" (ConnectionTimeout 15 (Conteiner nothing (Database "" (DataSource "c:\blokkies\blokkies.mdb" (Provider "Microsoft.jet.oledb.4.0" (Serverversion {"invalid operation. The connection is closed"} (Site Nothing (State Closed {0} 8. dim myoledbcommand nothing dbconn 9. after F8 (Myoledbcommand {system.data.oledb.oledbcommand} (commandtext "" (Commandtimeout 30 (commandtype text {1} (connection nothing (container nothing (designtimevisible true (parameters {system.data.oledb.oleparametercollection} (Site nothing (transaction nothing (updatedrowsource both {3} 10. myoledbcommand.connection = (oledbconn) (OleDbConn {system.data.oleDbConnection} (ConnectionString "Provider=microsoft.jet.oledb.4.0;data source=c:\blokkies\blokkies.mdb" (ConnectionTimeout 15 (Conteiner nothing (Database "" (DataSource "c:\blokkies\blokkies.mdb" (Provider "Microsoft.jet.oledb.4.0" (Serverversion "04.00.0000" (Site Nothing (State open {1} 11. myoledbcommand.commandtext =sqlstring = myoledbcommand.commandtext "" 12. After F8 =sqlstring = "select*from tblokkies where luidraad=Hendrik"
hendrikbez wrote:
12. After F8 =sqlstring = "select*from tblokkies where luidraad=Hendrik" = myoledbcommand.commandtext = "select*from tblokkies where luidraad=Hendrik"
I think Hendrik must be enclosed with '. SqlStr = "Select * from tblokkies where luidraad = '" & ListBox1.Items(ListBox1.SelectedIndex) & "'" try with select * from tblokkies where luidraad='Hendrik' from Access
-
hendrikbez wrote:
12. After F8 =sqlstring = "select*from tblokkies where luidraad=Hendrik" = myoledbcommand.commandtext = "select*from tblokkies where luidraad=Hendrik"
I think Hendrik must be enclosed with '. SqlStr = "Select * from tblokkies where luidraad = '" & ListBox1.Items(ListBox1.SelectedIndex) & "'" try with select * from tblokkies where luidraad='Hendrik' from Access
celso_cabaleiro Thank you it is working. I don't know how to do it, can you help me with this please I want to use txtluidraad.text to do a search, and then when I type in the word, listbox must go to that one, must I add a new listbox or will the one that I have work. I don 't know how to use a search at all. Hope you can help me.