Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to SEARCH values from database on Run time depend upon value in text box .NET 2.0.

Author: DevASP
Download Source Code : 593_VALUES_RUN_TIME_COMBO.zip

In this simple article you will learn that how you can SEARCH values from database on Run time depend upon value in text box.

Simply just create New Project of console application in VB.

 

Drag one text box, one Combo box on form.

 

In this sample I am using MS Access database and getting values from access on run time. This is a good example for beginners.

 

Import this library

 

Imports ss = System.Data.SqlClient

 

Now declare global variables

 

 

 

Dim cn As New System.Data.OleDb.OleDbConnection

  Dim cm As New System.Data.OleDb.OleDbCommand

  Dim rd As System.Data.OleDb.OleDbDataReader

 

Now just write code against these events

 

 

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=abc.mdb"

        Try

            cn.Open()

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

 

        cmbbyName.Items.Clear()

        cm.Connection = cn

        cm.CommandText = "select * from pDetails where Name like '" & txtbyName.Text & "%'"

        rd = cm.ExecuteReader()

 

        cmbbyName.Items.Clear()

 

        While (rd.Read)

            cmbbyName.Items.Add(rd("Name"))

        End While

 

        rd.Close()

 

        If cmbbyName.Items.Count > 0 Then

            cmbbyName.SelectedIndex = 0

        End If

 

        cn.Close()

        cmbbyName.DroppedDown = True

 

    End Sub

 

    Private Sub txtbyName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtbyName.TextChanged

        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=abc.mdb"

        Try

            cn.Open()

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

 

        cmbbyName.Items.Clear()

        cm.Connection = cn

        cm.CommandText = "select * from pDetails where Name like '" & txtbyName.Text & "%'"

        rd = cm.ExecuteReader()

 

        Try

            cmbbyName.Items.Clear()

 

            While (rd.Read)

                cmbbyName.Items.Add(rd("Name"))

            End While

            rd.Close()

 

            If cmbbyName.Items.Count > 0 Then

                cmbbyName.SelectedIndex = 0

            End If

 

 

 

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        Finally

            cn.Close()

        End Try

 

        cmbbyName.DroppedDown = True

    End Sub

 

 

 

Article Comments
Hello sir/madam,
This article is very nice.i need to implement this article in Asp.net using Vb.net.pls help me
Thank u

Posted on 1/9/2007 5:58:45 AM by Ancilla

THIS SOURCE CODE IS CRYSTAL CLEAR
FOR ME THOUGH I AM NEW TO VB.NET
THANK U

Posted on 10/4/2007 6:48:58 AM by ASHQ

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Creating an On screen Digital clock in VB.net

Disclaimer - Privacy
© 2002-2017 DevASP.net