|
-
Mar 22nd, 2004, 07:16 AM
#1
Thread Starter
Addicted Member
SQL SELECT Statement with ListView
Hey im trying to fill a ListView object with data selected from an SQL SELECT command
but im not sure how to do it
here is my code i have attempted:
Code:
Dim mySqlCommand As sqlcommand = New SqlCommand
mySqlCommand.CommandType = CommandType.Text
mySqlCommand.Connection = SqlConnection1
mySqlCommand.CommandType = CommandType.Text
mySqlCommand.CommandText = "SELECT showID, showTitle, showOwner FROM shows WHERE showOwner LIKE @showOwner;"
mySqlCommand.Parameters.Add(New SqlParameter("@showOwner", SqlDbType.VarChar))
mySqlCommand.Parameters("@showOwner").Value = System.Environment.UserName
Try
mySqlCommand.Connection.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
mySqlCommand.Connection.Close()
im not sure but do u have to declare a datareader then initiate a while loop
thanks
-
Mar 22nd, 2004, 07:43 AM
#2
I wonder how many charact
Re: SQL SELECT Statement with ListView
Yes sir, that's all you needed to add.
VB Code:
Dim mySqlCommand As sqlcommand = New SqlCommand
mySqlCommand.CommandType = CommandType.Text
mySqlCommand.Connection = SqlConnection1
mySqlCommand.CommandType = CommandType.Text
mySqlCommand.CommandText = "SELECT showID, showTitle, showOwner FROM shows WHERE showOwner LIKE @showOwner;"
mySqlCommand.Parameters.Add(New SqlParameter("@showOwner", SqlDbType.VarChar))
mySqlCommand.Parameters("@showOwner").Value = System.Environment.UserName
[b]Dim dr As System.Data.SqlClient.SqlDataReader[/b]
Try
SqlConnection1.Open
[b]dr = mySqlCommand.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
MyListView.Items.Add(dr(0))
End While[/b]
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
[b]dr.Close[/b]
End Try
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|