Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 21st, 2006, 03:21 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default "Identifier expected" Error

I am trying to compile the following code but am getting an "Identifier expected" error on Line 1:

Private Sub btnExecute_Click(ByVal sender As System.Object,_
 ByVal e As System.EventArgs) Handles btnExecute.Click
    Dim cmd As SqlCommand = SqlConnection1.CreateCommand
    cmd.CommandType = CommandType.text
    cmd.CommandText = txtQuery.text
    Dim da As SqlDataAdapter = New SqlDataAdapter
    da.SelectCommand = cmd
    Dim ds As DataSet = New DataSet
    da.Fill(ds, "Results")
    dgResults.DataSource = ds
    dgResults.DataMember = "Results"
End Sub

Could anyone please advise why this might be?

Many thanks,

Neha
 
Old January 22nd, 2006, 11:24 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Doesn't the compiler tell you where specifically the error is (in the line)? Also, which line is #1? The function declaration or the first line of the function?

-Peter
 
Old January 22nd, 2006, 12:01 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The error is in the first line (at the end of the line)',_'

Many thanks.
 
Old January 23rd, 2006, 01:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Take out the underscore ("_") in your first line.

J
 
Old January 23rd, 2006, 11:41 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need a space between the , and _.

Private Sub btnExecute_Click(ByVal sender As System.Object, _

-Peter
 
Old January 23rd, 2006, 06:44 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have removed the space and am still getting the same error.
Removing the underscore generates the same error aswell.

 
Old January 23rd, 2006, 11:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

No, he said you need to add a space, not remove it. In his example:

Private Sub btnExecute_Click(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles btnExecute.Click
        Dim cmd As SqlCommand = SqlConnection1.CreateCommand
        cmd.CommandType = CommandType.Text
        cmd.CommandText = txtQuery.text
        Dim da As SqlDataAdapter = New SqlDataAdapter
        da.SelectCommand = cmd
        Dim ds As DataSet = New DataSet
        da.Fill(ds, "Results")
        dgResults.DataSource = ds
        dgResults.DataMember = "Results"
    End Sub



Or in mine, I forgot to add that if you take out the underscore, you need to have it all on the first line like this:

Private Sub btnExecute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExecute.Click
        Dim cmd As SqlCommand = SqlConnection1.CreateCommand
        cmd.CommandType = CommandType.Text
        cmd.CommandText = txtQuery.text
        Dim da As SqlDataAdapter = New SqlDataAdapter
        da.SelectCommand = cmd
        Dim ds As DataSet = New DataSet
        da.Fill(ds, "Results")
        dgResults.DataSource = ds
        dgResults.DataMember = "Results"
    End Sub

All of this:

Private Sub btnExecute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExecute.Click


is on a single line, not broken over two lines.




Similar Threads
Thread Thread Starter Forum Replies Last Post
<identifier> expected error sprinkle Java Basics 1 February 11th, 2007 09:56 PM
"identifier> expected"error simmy_tj VB.NET 2002/2003 Basics 1 December 18th, 2006 08:31 AM
Identifier expected andriy JSP Basics 0 November 1st, 2006 11:28 PM
Identifier Expected syncmaster VB.NET 2002/2003 Basics 1 September 2nd, 2004 03:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.