Problem in SQL Connectivity code
-
Hi, The following code is generating an error....I have put comments in front of the line that generated error. Can anybody help me in this? :) Thanks,:):-O Public Sub ConnectSQL() Dim conn As New SqlClient.SqlConnection Dim da As New SqlClient.SqlDataAdapter da = SqlDataAdapter1
'This Adapter is manually created using the Wizard
conn = SqlConnection1'This Connection is manually created using the Wizard
Dim selectCommand As New SqlClient.SqlCommand("SELECT cFName from PersonalDetails")'Selecting The first column from the table
da.SelectCommand = selectCommand Dim Reader As SqlClient.SqlDataReader Dim RecordCount As Integer = 0 conn.Open() Reader = selectCommand.ExecuteReader()'This line is generating an error!!
Dim Records As String While Reader.Read() Dim i As Integer = 0 For i = 0 To Reader.FieldCount - 1 Records &= Reader(i) & "-" Next RecordCount += 1 End While -
Hi, The following code is generating an error....I have put comments in front of the line that generated error. Can anybody help me in this? :) Thanks,:):-O Public Sub ConnectSQL() Dim conn As New SqlClient.SqlConnection Dim da As New SqlClient.SqlDataAdapter da = SqlDataAdapter1
'This Adapter is manually created using the Wizard
conn = SqlConnection1'This Connection is manually created using the Wizard
Dim selectCommand As New SqlClient.SqlCommand("SELECT cFName from PersonalDetails")'Selecting The first column from the table
da.SelectCommand = selectCommand Dim Reader As SqlClient.SqlDataReader Dim RecordCount As Integer = 0 conn.Open() Reader = selectCommand.ExecuteReader()'This line is generating an error!!
Dim Records As String While Reader.Read() Dim i As Integer = 0 For i = 0 To Reader.FieldCount - 1 Records &= Reader(i) & "-" Next RecordCount += 1 End WhileThe Problem is you are not setting the connection or command type of your select command. Add these two lines right before you execure the reader
selectCommand.Connection = conn selectCommand.CommandText = CommandType.Text
Hope this works Kevin -
The Problem is you are not setting the connection or command type of your select command. Add these two lines right before you execure the reader
selectCommand.Connection = conn selectCommand.CommandText = CommandType.Text
Hope this works Kevin