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. "Declaration expected"

"Declaration expected"

Scheduled Pinned Locked Moved Visual Basic
designsecurityhelp
8 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.
  • K Offline
    K Offline
    kenn_rosie
    wrote on last edited by
    #1

    In my code below, When I go to a new line, it will not let me put the ( ) at the end of Dim ds As New DataSet I can enter the parenthesis () but it removes them when I go to a new line Also the dataAdapter.Fill(ds, "progs") gives me the error "Declaration expected" Here is mycode so far: ************************** ************************** Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Dim connectionString As String = "workstation id=Dude;packet size=4096;integrated security=SSPI;data source=Dozer;" & _ "persist security info=False;initial catalog=programmersheaven" Dim conn As New SqlConnection(connectionString) Dim commandString As String = "SELECT " + _ "artId, title, topic, " + _ "article.authorId as authorId, " + _ "name, lines, dateOfPublishing " + _ "FROM " + _ "article, author " + _ "WHERE " + _ "author.authorId = article.authorId" Dim dataAdapter As New SqlDataAdapter(commandString, conn) Dim ds As New DataSet dataAdapter.Fill(ds, "progs")

    G 1 Reply Last reply
    0
    • K kenn_rosie

      In my code below, When I go to a new line, it will not let me put the ( ) at the end of Dim ds As New DataSet I can enter the parenthesis () but it removes them when I go to a new line Also the dataAdapter.Fill(ds, "progs") gives me the error "Declaration expected" Here is mycode so far: ************************** ************************** Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Dim connectionString As String = "workstation id=Dude;packet size=4096;integrated security=SSPI;data source=Dozer;" & _ "persist security info=False;initial catalog=programmersheaven" Dim conn As New SqlConnection(connectionString) Dim commandString As String = "SELECT " + _ "artId, title, topic, " + _ "article.authorId as authorId, " + _ "name, lines, dateOfPublishing " + _ "FROM " + _ "article, author " + _ "WHERE " + _ "author.authorId = article.authorId" Dim dataAdapter As New SqlDataAdapter(commandString, conn) Dim ds As New DataSet dataAdapter.Fill(ds, "progs")

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You don't need the paranthesis when there is no parameters, oddly enough. You can't put code outside a method, only declarations. --- b { font-weight: normal; }

      K 1 Reply Last reply
      0
      • G Guffa

        You don't need the paranthesis when there is no parameters, oddly enough. You can't put code outside a method, only declarations. --- b { font-weight: normal; }

        K Offline
        K Offline
        kenn_rosie
        wrote on last edited by
        #3

        I moved my code under sub page_load but it still need not work? Sorry, I am so very new at this Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim connectionString As String = "workstation id=DOZER;packet size=4096;integrated security=SSPI;data source=Dozer;" & _ "persist security info=False;initial catalog=programmersheaven" Dim conn As New SqlConnection(connectionString) Dim commandString As String = "SELECT " + _ "artId, title, topic, " + _ "article.authorId as authorId, " + _ "name, lines, dateOfPublishing " + _ "FROM " + _ "article, author " + _ "WHERE " + _ "author.authorId = article.authorId" Dim dataAdapter As New SqlDataAdapter(commandString, conn) Dim ds As New DataSet dataAdapter.Fill(ds, "prog") Dim dataTable As DataTable = ds.Tables("prog") End Sub

        G 1 Reply Last reply
        0
        • K kenn_rosie

          I moved my code under sub page_load but it still need not work? Sorry, I am so very new at this Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim connectionString As String = "workstation id=DOZER;packet size=4096;integrated security=SSPI;data source=Dozer;" & _ "persist security info=False;initial catalog=programmersheaven" Dim conn As New SqlConnection(connectionString) Dim commandString As String = "SELECT " + _ "artId, title, topic, " + _ "article.authorId as authorId, " + _ "name, lines, dateOfPublishing " + _ "FROM " + _ "article, author " + _ "WHERE " + _ "author.authorId = article.authorId" Dim dataAdapter As New SqlDataAdapter(commandString, conn) Dim ds As New DataSet dataAdapter.Fill(ds, "prog") Dim dataTable As DataTable = ds.Tables("prog") End Sub

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Standard question #1: What do you mean by "not working"? Standard question #2: What error message do you get? --- b { font-weight: normal; }

          K 1 Reply Last reply
          0
          • G Guffa

            Standard question #1: What do you mean by "not working"? Standard question #2: What error message do you get? --- b { font-weight: normal; }

            K Offline
            K Offline
            kenn_rosie
            wrote on last edited by
            #5

            Thanks for replying, First I have been taking a tutorial from

            G 1 Reply Last reply
            0
            • K kenn_rosie

              Thanks for replying, First I have been taking a tutorial from

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              The error message "Declaration Expected" means exactly what is says. You have code where only declarations are allowed. I already explained this. As it's a compiler error message, it has nothing what so ever to do with the database. The database doesn't even have to exist for the code to compile. Of course you are getting a blank page. What else could you get? You load some data from the database, then you don't do anything with it. What could possibly show up on the page? --- b { font-weight: normal; }

              K 1 Reply Last reply
              0
              • G Guffa

                The error message "Declaration Expected" means exactly what is says. You have code where only declarations are allowed. I already explained this. As it's a compiler error message, it has nothing what so ever to do with the database. The database doesn't even have to exist for the code to compile. Of course you are getting a blank page. What else could you get? You load some data from the database, then you don't do anything with it. What could possibly show up on the page? --- b { font-weight: normal; }

                K Offline
                K Offline
                kenn_rosie
                wrote on last edited by
                #7

                Thanks again, I am getting closer for a lowly Newbie. I appreciate your getting me closer. Now I must figure what I am doing wrong to get it to display on the browser. Probably something extremely simple but I don't know what that is. Thanks for getting me this far. At least I no longer have the "Declaration expected" problem. I was hoping that the following code would display to the browser: Dim ds As New DataSet dataAdapter.Fill(ds, "arthor,article") Dim dataTable As DataTable = ds.Tables("arthur,article")

                G 1 Reply Last reply
                0
                • K kenn_rosie

                  Thanks again, I am getting closer for a lowly Newbie. I appreciate your getting me closer. Now I must figure what I am doing wrong to get it to display on the browser. Probably something extremely simple but I don't know what that is. Thanks for getting me this far. At least I no longer have the "Declaration expected" problem. I was hoping that the following code would display to the browser: Dim ds As New DataSet dataAdapter.Fill(ds, "arthor,article") Dim dataTable As DataTable = ds.Tables("arthur,article")

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  You have to put something on the page for it to show up in the browser. You can for an example put a DataGrid on the page, and use the DataTable as DataSource for the grid. --- b { font-weight: normal; }

                  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