0

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 by poksmdpk: wrong title

2
Contributors
4
Replies
16
Views
3 Years
Discussion Span
Last Post by poksmdpk
0

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 by ryanjayson

0

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 by poksmdpk: wrong grammar

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.