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

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

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

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.

thx sir! i owe you

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.