hey friends, i am new to vb.net so i have a problem to sort out.Can u pls help me.
In my form i have a combobox and textbox,when i select an value from combobox then in the txtbox it has to automatically generate value (from database) corresponding to value selected in combobox.For clear understanding suppose,if i selected an name of the student frm combobox then in the txtbox it has to display the rollno corresponding to tat name...
pls help me.And thanks in advance..

Recommended Answers

All 4 Replies

Write a method or function which accepts the parameter of ur combotext, In the method or function write a code which connects to DB and fetches the records from DB based on the parameter. Call this method or function in selected index changed event of combo. Hope this gives you some basic idea.. Happy coding in vb.net :)

using select statement and in the where clause mention the criteria as ur combo box....and in ur reader assign the value to the text box....

     Dim myCommand As SqlCommand
     myCommand = New SqlCommand("SELECT  * FROM tablename where studentname='" & Combobox1.Text & "'", Connection)
     Dim reader As SqlDataReader = myCommand.ExecuteReader
     While reader.Read
           txtRollID.Text = reader("RollID")
     End While
Catch ex As Exception
     MsgBox("Error Connecting to Database: " & ex.Message)
End Try
i use Oledb But you can use it into SQL just translate it:)

put this into the button you want to roll over or Event that would make it

Connection ' Set Your Connection
sql = "SELECT MAX(ID) AS RollNumber FROM YOURTABLES  'SQL Statement
cmd = New Oledb.OledbCommand(sql,con) 'cmd = Oledb.OledbCommand
dr = cmd.executereader 'dr = DataReader

while dr.read
    lbRollNumber.text = Val(dr("RollNumber")) + 1
end while


This will generate a value added only 1 'Well i guess it would do the trick or maybe you will use a random function from which i dont like :).

hey thanks to pgmer,poojavb & denden17 for ur replys!!! i got it...tanx again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.