.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get Data Of One Field From The Another Selected Field From The Combobox

Posted By:Ghanashyam Nayak       Posted Date: January 31, 2011    Points: 15    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

Code To Get Data into The Text box From The Another Field From The Combo box...
 


Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        	Dim Conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/MyDatabase1.mdb")
        	Dim dr As OleDbDataReader
        	Try
		Conn.Open()
		Dim cmd As OleDbCommand = New OleDbCommand("Select StudentName From Student Where StudentId=" & ComboBox1.SelectedItem.ToString() & "", Conn)
		dr = cmd.ExecuteReader
		While dr.Read()
			txtStudentName.Text = dr.GetValue(0).ToString()
		End While
		Conn.Close()
	Catch ex As Exception
		MessageBox.Show(ex.ToString())
	Finally
		Conn.Close()
		dr.Close()
	End Try
End Sub


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend