Hello everyone, this is my first post here. I was hoping someone could help me out with a question that has been bugging me.
I'm working with ADO.NET and I have the following code (using untyped datasets):
Imports System.Data.SqlClient
PublicClass Form1
Inherits System.Windows.Forms.Form
Dim daStudentRec As New SqlDataAdapter
Dim cnDIYH As New SqlConnection
Dim cmStudentSelect As New SqlCommand
Dim dsStudents As New DataSet
....
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
Dim sConnectString AsString
Dim drStudent As DataRow
sConnectString = "server = 8001sbab1; database = DIYH; integrated security = SSPI"
cnDIYH.ConnectionString = sConnectString
With cmStudentSelect
.Connection = cnDIYH
.CommandText = "Select SSN,Lname,Fname from StudentRecord where left(SSN,1)='A'"
EndWith
daStudentRec.SelectCommand = cmStudentSelect
daStudentRec.Fill(dsStudents)
drStudent = dsStudents.Tables(0).Rows(0)
txtSSN.Text = drStudent.Item("SSN")
EndSub
This code works and the first SSN from the first record is displayed in the textbox. Simple, I know. Just wanted to learn and test things out.
The confusion I have is with the NEW keyword. Why is the NEW keyword required when declaring the data adapter,dataset,connection and command objects and not required when declaring the datarow in my Load procedure?
In fact, if I code the NEW keyword in that line, an error is generated. How come? Isn't the datarow also a class? How do I know when to use it and when not to (other than relying on Intellisense).
I'm working with ADO.NET and I have the following code (using untyped datasets):
Imports System.Data.SqlClient
PublicClass Form1
Inherits System.Windows.Forms.Form
Dim daStudentRec As New SqlDataAdapter
Dim cnDIYH As New SqlConnection
Dim cmStudentSelect As New SqlCommand
Dim dsStudents As New DataSet
....
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
Dim sConnectString AsString
Dim drStudent As DataRow
sConnectString = "server = 8001sbab1; database = DIYH; integrated security = SSPI"
cnDIYH.ConnectionString = sConnectString
With cmStudentSelect
.Connection = cnDIYH
.CommandText = "Select SSN,Lname,Fname from StudentRecord where left(SSN,1)='A'"
EndWith
daStudentRec.SelectCommand = cmStudentSelect
daStudentRec.Fill(dsStudents)
drStudent = dsStudents.Tables(0).Rows(0)
txtSSN.Text = drStudent.Item("SSN")
EndSub
This code works and the first SSN from the first record is displayed in the textbox. Simple, I know. Just wanted to learn and test things out.
The confusion I have is with the NEW keyword. Why is the NEW keyword required when declaring the data adapter,dataset,connection and command objects and not required when declaring the datarow in my Load procedure?
In fact, if I code the NEW keyword in that line, an error is generated. How come? Isn't the datarow also a class? How do I know when to use it and when not to (other than relying on Intellisense).