can anyone help me in this problem? i have to put sql server data in my combobox on my form, i watch several tutorial in youtube and read here some other codes but i still don't how to. please can anyone help me?

            Using combocon As New SqlConnection("Data Source=NSSISQLSERVER;Initial Catalog=NSSIDB;Persist Security Info=True;User ID=*******;Password=*****")
            combocon.Open()

            Dim xcom As String = "Select fldAssignTechnical from tbleRequestHistory"
            Dim comcmd As New SqlCommand(xcom, combocon)
            comcmd.CommandType = CommandType.Text

            Dim datadap As New SqlDataAdapter
            Dim dtable As New DataTable


            datadap.Fill(dtable)

            If dtable.Rows.Count = 0 Then
                MsgBox("No Existing List", MsgBoxStyle.Critical)
            Else
                For i = 0 To dtable.Rows.Count - 1
                    FldAssignTechnicalComboBox.Items.Add(dtable.Rows(i).Item("FldAssignTechnicalComboBox"))
                Next
            End If


        End Using
        FldAssignTechnicalComboBox.SelectedItem = 0

Inline Code Example Here

Edited 3 Years Ago by poksmdpk: wrong title

Try this simplified code:

Using combocon As New SqlConnection("Data Source=NSSISQLSERVER;Initial Catalog=NSSIDB;Persist Security Info=True;User ID=*******;Password=*****")
    Dim commd As OleDbCommand = New OleDbCommand("Select fldAssignTechnical from tbleRequestHistory", combocon)          
    combocon.Open()
    Dim dtaReadr As OleDbDataReader = commd.ExecuteReader
         While dtaReadr.Read()
            FldAssignTechnicalComboBox.Items.Add("FldAssignTechnicalComboBox").ToString)
         End While
    combocon.Close()
End Using

Edited 3 Years Ago by ryanjayson

sir this is c#.net? i used vb.net? why do you use OleDbCommand? OleDbCommand is for c#.net only, but correct me if i wrong

Edited 3 Years Ago by poksmdpk: wrong grammar

it is VB code. OleDBCommand(or OleDBDataReader, OleDBConnectiion etc,) is for DB like Access, just changes the OleDB to Sql (SqlDataReader and SqlCommand), becuase you are using SQL server. Hope you got it.

This question has already been answered. Start a new discussion instead.