C
Chris Strug
Hi,
My apologies if this is a simple question but I'm having a hard time making
any progress so...
I'm looking at VB ADO.net, moving from ADO / Access development.
I've created a bog standard windows app in VB2005 Express and having read
some of the basics am attempting to create a connection to a SQLS2000 db on
my network and display the contents of a table in a listbox on a my form.
As I understand it, the steps involved are:
* create a connection to the database (done, I think)
* create a command object containing the action that i wish to perform
(SELECT statement)
* execute the command object and return the reults set to a DataReader
object as read-only which I can use to populate the listbox on my form.
I can create the connection and the command object but I'm not quite sure
where the datareader object comes in and how exactly I use it...
Please see code below.
I appreciate that this is a very simple question, however any and all advice
is gratefully received - be that links, pointers or so on.
Thanks
Chris.
**************************
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim TLCConn As SqlClient.SqlConnection
Dim contCMD As SqlClient.SqlCommand
TLCConn = New SqlConnection
TLCConn.ConnectionString = _
"Data Source=SQL;Integrated Security=SSPI;Initial
Catalog=TLCBackup"
TLCConn.Open()
contCMD = New SqlCommand
contCMD.Connection = TLCConn
contCMD.CommandText = "SELECT MovementNo, ContainerNo, DateIn,
DateOut " & _
"FROM Stock " & _
"WHERE dateout is null " & _
"ORDER BY MovementNo"
End Sub
End Class
My apologies if this is a simple question but I'm having a hard time making
any progress so...
I'm looking at VB ADO.net, moving from ADO / Access development.
I've created a bog standard windows app in VB2005 Express and having read
some of the basics am attempting to create a connection to a SQLS2000 db on
my network and display the contents of a table in a listbox on a my form.
As I understand it, the steps involved are:
* create a connection to the database (done, I think)
* create a command object containing the action that i wish to perform
(SELECT statement)
* execute the command object and return the reults set to a DataReader
object as read-only which I can use to populate the listbox on my form.
I can create the connection and the command object but I'm not quite sure
where the datareader object comes in and how exactly I use it...
Please see code below.
I appreciate that this is a very simple question, however any and all advice
is gratefully received - be that links, pointers or so on.
Thanks
Chris.
**************************
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim TLCConn As SqlClient.SqlConnection
Dim contCMD As SqlClient.SqlCommand
TLCConn = New SqlConnection
TLCConn.ConnectionString = _
"Data Source=SQL;Integrated Security=SSPI;Initial
Catalog=TLCBackup"
TLCConn.Open()
contCMD = New SqlCommand
contCMD.Connection = TLCConn
contCMD.CommandText = "SELECT MovementNo, ContainerNo, DateIn,
DateOut " & _
"FROM Stock " & _
"WHERE dateout is null " & _
"ORDER BY MovementNo"
End Sub
End Class