"Declaration expected"
-
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")
-
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")
-
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; }
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
-
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
-
Standard question #1: What do you mean by "not working"? Standard question #2: What error message do you get? --- b { font-weight: normal; }
-
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; }
-
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; }
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")
-
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")