View Single Post
  #1 (permalink)  
Old June 29th, 2009, 03:46 PM
liamfitz liamfitz is offline
Authorized User
Points: 312, Level: 6
Points: 312, Level: 6 Points: 312, Level: 6 Points: 312, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Question Command Objects ( S.Q.L. in sub-routine ) ?

I'm trying to 'refresh' an existing dataset and DataGridView, using the following code, in a click-event routine. I'm sure I've got some of the objects/methods wrong. Can anyone assist ? ( Pages 424-427 ?)
Code:
 
PrivateSub btnSBig_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnSBig.Click
' open the connection.
Dim conn_initialcust AsNew OleDb.OleDbConnection(CONNECT_STRING)
conn_initialcust.Open()
' make a command to select the data
Dim cmd AsNew OleDb.OleDbCommand("SELECT Forename, [Middle Initial], Surname FROM Customers WHERE Surname LIKE 'S*';", conn_initialcust)
' execute the command.
Try
cmd.ExecuteReader()
Catch ex As Exception
MessageBox.Show(ex.Message)
EndTry
conn_initialcust.Close()
conn_initialcust.Dispose()
EndSub

I'm sure the problem's from the ' Dim cmd ' line onwards. Thanks.