Click here to Skip to main content
16,006,709 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionPopulate any combobox with table column using VB.NET WITH ORACLE DATABASE. Pin
nan4915-Jan-09 5:30
nan4915-Jan-09 5:30 
AnswerRe: Populate any combobox with table column using VB.NET WITH ORACLE DATABASE. Pin
Scott Dorman15-Jan-09 5:37
professionalScott Dorman15-Jan-09 5:37 
GeneralRe: Populate any combobox with table column using VB.NET WITH ORACLE DATABASE. Pin
Jon_Boy15-Jan-09 6:06
Jon_Boy15-Jan-09 6:06 
GeneralRe: Populate any combobox with table column using VB.NET WITH ORACLE DATABASE. Pin
Scott Dorman15-Jan-09 6:17
professionalScott Dorman15-Jan-09 6:17 
GeneralRe: Populate any combobox with table column using VB.NET WITH ORACLE DATABASE. Pin
Jon_Boy15-Jan-09 6:40
Jon_Boy15-Jan-09 6:40 
GeneralRe: Populate any combobox with table column using VB.NET WITH ORACLE DATABASE. Pin
leckey15-Jan-09 9:11
leckey15-Jan-09 9:11 
GeneralRe: Populate any combobox with table column using VB.NET WITH ORACLE DATABASE. Pin
Scott Dorman15-Jan-09 9:13
professionalScott Dorman15-Jan-09 9:13 
QuestionPopulate any combobox with table column using VB.NET WITH ORACLE DATABASE. Pin
nan4915-Jan-09 5:18
nan4915-Jan-09 5:18 
Here is a function to populate any combobox with data from a table column.This style wld work for any database. I prefer to use oracle in this instance.


You first have to create the function in a module or class 
and call it from anywhere in your project with the required parameters


<br />
<br />
'For instance, drop a combobox(combobox1) and a button(button1) and under the button add<br />
<br />
Private Sub Button1_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles Button1.Click<br />
<br />
'when calling from a class    <br />
'className.populateAnyCombo(comboboxName,"sql statment", _ <br />
'column name, connection string)<br />
<br />
'---call function from a module----<br />
<br />
PopulateAnyCombo(combobox1,"SQL(eg Select Column_Name from Table_Name)", _<br />
"column_name", connectionString)<br />
<br />
End Sub<br />
<br />
<br />
<br />
<br />
<br />
'----------Place in a module or class----------<br />
<br />
Public Function PopulateAnyCombo(ByVal cBox As ComboBox, ByVal strSQL  _<br />
As String, ByVal tableColumn As String,ByVal connString As String ) As String()<br />
<br />
        Dim array(0) As String<br />
        Dim cnt As Integer = 0<br />
        Dim conn As New OracleConnection<br />
<br />
        conn.ConnectionString = connString<br />
        Try<br />
            conn.Open()<br />
        Catch ex As Exception<br />
            MsgBox("Failed conection to Oracle" & ex.Message)<br />
            Return array<br />
         End Try<br />
<br />
        Dim cmd As New OracleCommand<br />
        With cmd<br />
            .CommandText = strSQL<br />
            .CommandType = CommandType.Text<br />
            .Connection = conn<br />
        End With<br />
        'data reader to store recordsets retrieved<br />
        Dim dr As OracleDataReader<br />
<br />
'Reading an populating records in array<br />
'ReDim preserve increases the array size and preserve old members<br />
        Try<br />
            dr = cmd.ExecuteReader<br />
            While dr.Read<br />
                ReDim Preserve array(cnt)<br />
                array(cnt) = dr.Item(tableColumn)<br />
                cnt = cnt + 1<br />
            End While<br />
         <br />
            cBox.Items.Clear()<br />
            cBox.Items.AddRange(array)<br />
<br />
            Return array<br />
        Catch ex As Exception<br />
<br />
            Dim a(0) As String<br />
            a(0) = 0<br />
            Return a<br />
        Finally<br />
            conn.Close()<br />
            conn.Dispose()<br />
        End Try<br />
    End Function<br />
<br />
'-----------------place in a module or class-------------<br />
<br />


Would be glad to know if i helped solve a problem 
Criticisms to this snippet are welcomed
nan492001@yahoo.com

AnswerRe: Populate any combobox with table column using VB.NET WITH ORACLE DATABASE. Pin
dan!sh 15-Jan-09 5:21
professional dan!sh 15-Jan-09 5:21 
GeneralRe: Populate any combobox with table column using VB.NET WITH ORACLE DATABASE. Pin
leckey15-Jan-09 9:10
leckey15-Jan-09 9:10 
Questiononselectedindexchanged Pin
Franklinlloyd15-Jan-09 5:00
Franklinlloyd15-Jan-09 5:00 
AnswerRe: onselectedindexchanged Pin
Scott Dorman15-Jan-09 5:04
professionalScott Dorman15-Jan-09 5:04 
AnswerRe: onselectedindexchanged Pin
Franklinlloyd15-Jan-09 5:08
Franklinlloyd15-Jan-09 5:08 
General[Forum Redirect] onselectedindexchanged Pin
Scott Dorman15-Jan-09 5:29
professionalScott Dorman15-Jan-09 5:29 
QuestionHow to set datasource of On-demand subreport in crystal report Pin
Ali 11014-Jan-09 23:55
Ali 11014-Jan-09 23:55 
Questionwhat is right way to handle? Pin
srisant14-Jan-09 20:45
srisant14-Jan-09 20:45 
AnswerRe: what is right way to handle? Pin
N a v a n e e t h14-Jan-09 23:02
N a v a n e e t h14-Jan-09 23:02 
GeneralRe: what is right way to handle? Pin
Manas Bhardwaj15-Jan-09 2:01
professionalManas Bhardwaj15-Jan-09 2:01 
GeneralRe: what is right way to handle? Pin
N a v a n e e t h16-Jan-09 5:05
N a v a n e e t h16-Jan-09 5:05 
QuestionVb integration with mainframe Pin
usharaniA14-Jan-09 20:24
usharaniA14-Jan-09 20:24 
AnswerRe: Vb integration with mainframe Pin
Ashfield15-Jan-09 1:24
Ashfield15-Jan-09 1:24 
AnswerRe: Vb integration with mainframe Pin
Dave Kreskowiak15-Jan-09 4:30
mveDave Kreskowiak15-Jan-09 4:30 
QuestionDataGridViewCombobox EditingControlShowing event Pin
sahahima14-Jan-09 19:12
sahahima14-Jan-09 19:12 
AnswerRe: DataGridViewCombobox EditingControlShowing event Pin
Dave Kreskowiak15-Jan-09 4:27
mveDave Kreskowiak15-Jan-09 4:27 
QuestionRe: DataGridViewCombobox EditingControlShowing event Pin
sahahima15-Jan-09 19:35
sahahima15-Jan-09 19:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.