[IWE] broomberg - maybe this will help
golf_lover44
iwe@warhead.org.uk
Sat, 13 Jan 2007 12:48:35 -0800 (PST)
It's written in VB.Net, but you should be able to translate it to C#.
Private Sub FillListBox()
Dim strColumnName As String
Dim strbuffer As String
Dim strbuffer2 As String
Dim ConnectionInfo As String
Dim numcols As Integer
Dim k As Integer
ConnectionInfo =
"server=(local);database=Northwind;uid=sa;pwd=;Integrated
Security=SSPI"
Dim con3 As New SqlConnection(ConnectionInfo)
CommandLine = "SELECT * FROM Authors WHERE LastName = 'Smith'"
Dim cmd3 As New SqlCommand(CommandLine, con3)
Dim daLocal As New SqlDataAdapter(CommandLine, con3)
Dim ds As New DataSet("Authors")
Try
con3.Open()
daLocal.Fill(ds)
Dim myTable As DataTable = ds.Tables(0)
numcols = myTable.Columns.Count
Dim row As DataRow
'For Each row In myTable.Rows
For k = 0 To numcols - 1
strbuffer = myTable.Columns(k).ColumnName
strbuffer2 = strbuffer & " = '" &
ds.Tables(0).Rows(0)(strbuffer) & "'"
ListBox2.Items.Add(strbuffer2)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
con3.Close()
End Try
End Sub
____________________________________________________________________________________
Have a burning question?
Go to www.Answers.yahoo.com and get answers from real people who know.