Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem in SQL Connectivity code

Problem in SQL Connectivity code

Scheduled Pinned Locked Moved Visual Basic
helpdatabasequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    united18
    wrote on last edited by
    #1

    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

    K 1 Reply Last reply
    0
    • U united18

      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

      K Offline
      K Offline
      Kevin Nicol
      wrote on last edited by
      #2

      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

      U 1 Reply Last reply
      0
      • K Kevin Nicol

        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

        U Offline
        U Offline
        united18
        wrote on last edited by
        #3

        Hi Kevin I added the above lines of code. I am getting the same error. However, Thanks for your help :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups