By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,745 Members | 812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,745 IT Pros & Developers. It's quick & easy.

Declaration Expected?

P: n/a
Still learning ASP.NET....(and I was getting so good with classic ASP too!).

I'm trying to connect to a SQL Server using a simple connection script.
I've checked 2 different books and looked at www.asp.net and still cannot
get past this "error".

Can anyone see the error? This <script> example is almost line by line from
the Sams ASP.NET Unleashed Book. The error is on line 8. Thanks.

Compiler Error Message: BC30188: Declaration expected.

Source Error:

Line 8: DbConn = New SQLConnection("server=drpt-server3;
database=DRPT-TEST")
**********************************

<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Dim DbConn As SQLConnection
Dim MySQLCommand As SQLCommand
Dim RS As SQLDataReader

DbConn = New SQLConnection("server=drpt-server3; database=DRPT-TEST")
DbConn.Open()

MySQLCommand = New MySQLCommand("SELECT * FROM Staff;", DbConn)
RS = MySQLCommand.ExecuteReader()
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<%
RS.MoveFirst
Response.Write RS("LastName").Value

DbConn.Close()
RS.Close()
%>
</body>
</html>

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************

Nov 18 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
what is the error?
-----Original Message-----
Still learning ASP.NET....(and I was getting so good with classic ASP too!).
I'm trying to connect to a SQL Server using a simple connection script.I've checked 2 different books and looked at www.asp.net and still cannotget past this "error".

Can anyone see the error? This <script> example is almost line by line fromthe Sams ASP.NET Unleashed Book. The error is on line 8. Thanks.
Compiler Error Message: BC30188: Declaration expected.

Source Error:

Line 8: DbConn = New SQLConnection("server=drpt-server3;
database=DRPT-TEST")
**********************************

<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Dim DbConn As SQLConnection
Dim MySQLCommand As SQLCommand
Dim RS As SQLDataReader

DbConn = New SQLConnection("server=drpt-server3; database=DRPT-TEST") DbConn.Open()

MySQLCommand = New MySQLCommand("SELECT * FROM Staff;", DbConn) RS = MySQLCommand.ExecuteReader()
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<%
RS.MoveFirst
Response.Write RS("LastName").Value

DbConn.Close()
RS.Close()
%>
</body>
</html>

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************

.

Nov 18 '05 #2

P: n/a
Hmm...

Have you tried putting RS.Read after RS.MoveFirst?

Also, once you're getting good with DataReaders, you might want to consider
ditching them in favour of DataSets. Much nicer.

Also - DON'T forget to DbConn.Dispose()
Regards,
Anth

"D. Shane Fowlkes" <sh***@raccoonbob.com> wrote in message
news:O6**************@TK2MSFTNGP12.phx.gbl...
Still learning ASP.NET....(and I was getting so good with classic ASP too!).
I'm trying to connect to a SQL Server using a simple connection script.
I've checked 2 different books and looked at www.asp.net and still cannot
get past this "error".

Can anyone see the error? This <script> example is almost line by line from the Sams ASP.NET Unleashed Book. The error is on line 8. Thanks.

Compiler Error Message: BC30188: Declaration expected.

Source Error:

Line 8: DbConn = New SQLConnection("server=drpt-server3;
database=DRPT-TEST")
**********************************

<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Dim DbConn As SQLConnection
Dim MySQLCommand As SQLCommand
Dim RS As SQLDataReader

DbConn = New SQLConnection("server=drpt-server3; database=DRPT-TEST")
DbConn.Open()

MySQLCommand = New MySQLCommand("SELECT * FROM Staff;", DbConn)
RS = MySQLCommand.ExecuteReader()
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<%
RS.MoveFirst
Response.Write RS("LastName").Value

DbConn.Close()
RS.Close()
%>
</body>
</html>

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************

Nov 18 '05 #3

P: n/a
I included it in my post.

Thx

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************
"Jon Paugh" <an*******@discussions.microsoft.com> wrote in message
news:26****************************@phx.gbl...
what is the error?
-----Original Message-----
Still learning ASP.NET....(and I was getting so good with

classic ASP too!).

I'm trying to connect to a SQL Server using a simple

connection script.
I've checked 2 different books and looked at www.asp.net

and still cannot
get past this "error".

Can anyone see the error? This <script> example is

almost line by line from
the Sams ASP.NET Unleashed Book. The error is on line

8. Thanks.

Compiler Error Message: BC30188: Declaration expected.

Source Error:

Line 8: DbConn = New SQLConnection("server=drpt-server3;
database=DRPT-TEST")
**********************************

<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Dim DbConn As SQLConnection
Dim MySQLCommand As SQLCommand
Dim RS As SQLDataReader

DbConn = New SQLConnection("server=drpt-server3;

database=DRPT-TEST")
DbConn.Open()

MySQLCommand = New MySQLCommand("SELECT * FROM Staff;",

DbConn)
RS = MySQLCommand.ExecuteReader()
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<%
RS.MoveFirst
Response.Write RS("LastName").Value

DbConn.Close()
RS.Close()
%>
</body>
</html>

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************

.

Nov 18 '05 #4

P: n/a
Yeah...here's the new code but same error. It wants me to "declare" my
DbConn = New SQLConnection....." line. I don't get it.

...frustrated...
<% @Page Language = "VB" Debug = "True" Explicit = "True" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Dim DbConn As SQLConnection
Dim MySQLCommand As SQLCommand
Dim RS As SQLDataReader

DbConn = New SQLConnection("server=drpt-server3; database=DRPT-TEST")
DbConn.Open()

MySQLCommand = New MySQLCommand("SELECT * FROM Staff;", DbConn)
RS = MySQLCommand.ExecuteReader()
</script>

<html>
<head>
</head>
<body>
<%
RS.MoveFirst
RS.Read()
Response.Write RS("LastName").Value
DbConn.Close()
RS.Close()
%>
</body>
</html>

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************
"Anthony Williams" <to**@bigtone.net> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
Hmm...

Have you tried putting RS.Read after RS.MoveFirst?

Also, once you're getting good with DataReaders, you might want to consider ditching them in favour of DataSets. Much nicer.

Also - DON'T forget to DbConn.Dispose()
Regards,
Anth

"D. Shane Fowlkes" <sh***@raccoonbob.com> wrote in message
news:O6**************@TK2MSFTNGP12.phx.gbl...
Still learning ASP.NET....(and I was getting so good with classic ASP

too!).

I'm trying to connect to a SQL Server using a simple connection script.
I've checked 2 different books and looked at www.asp.net and still cannot get past this "error".

Can anyone see the error? This <script> example is almost line by line

from
the Sams ASP.NET Unleashed Book. The error is on line 8. Thanks.

Compiler Error Message: BC30188: Declaration expected.

Source Error:

Line 8: DbConn = New SQLConnection("server=drpt-server3;
database=DRPT-TEST")
**********************************

<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Dim DbConn As SQLConnection
Dim MySQLCommand As SQLCommand
Dim RS As SQLDataReader

DbConn = New SQLConnection("server=drpt-server3; database=DRPT-TEST")
DbConn.Open()

MySQLCommand = New MySQLCommand("SELECT * FROM Staff;", DbConn)
RS = MySQLCommand.ExecuteReader()
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<%
RS.MoveFirst
Response.Write RS("LastName").Value

DbConn.Close()
RS.Close()
%>
</body>
</html>

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************


Nov 18 '05 #5

P: n/a
unlike asp, only subroutines and functions are allowed in <script
runat=server> blocks. inline code is only allowed in with <% %>

-- bruce (sqlwork.com)

"D. Shane Fowlkes" <sh***@raccoonbob.com> wrote in message
news:O6**************@TK2MSFTNGP12.phx.gbl...
Still learning ASP.NET....(and I was getting so good with classic ASP too!).
I'm trying to connect to a SQL Server using a simple connection script.
I've checked 2 different books and looked at www.asp.net and still cannot
get past this "error".

Can anyone see the error? This <script> example is almost line by line from the Sams ASP.NET Unleashed Book. The error is on line 8. Thanks.

Compiler Error Message: BC30188: Declaration expected.

Source Error:

Line 8: DbConn = New SQLConnection("server=drpt-server3;
database=DRPT-TEST")
**********************************

<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Dim DbConn As SQLConnection
Dim MySQLCommand As SQLCommand
Dim RS As SQLDataReader

DbConn = New SQLConnection("server=drpt-server3; database=DRPT-TEST")
DbConn.Open()

MySQLCommand = New MySQLCommand("SELECT * FROM Staff;", DbConn)
RS = MySQLCommand.ExecuteReader()
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<%
RS.MoveFirst
Response.Write RS("LastName").Value

DbConn.Close()
RS.Close()
%>
</body>
</html>

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************

Nov 18 '05 #6

P: n/a
Oh, IC, sorry. Try:

Dim DbConn As new SQLConnection("server=drpt-
server3; database=DRPT-TEST")
Dim MySQLCommand As SQLCommand
Dim RS As SQLDataReader

Sub Page_Load(Sender As Object, E As
EventArgs)
DbConn = New SQLConnection("server=drpt-server3;
database=DRPT-TEST")
DbConn.Open()

MySQLCommand = New SQLCommand("SELECT * FROM
Staff;", DbConn)
RS = MySQLCommand.ExecuteReader()
End Sub

(you didnt have code in a method and you were trying to
create a MySQLCommand too, which is not a type)
-----Original Message-----
I included it in my post.

Thx

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************
"Jon Paugh" <an*******@discussions.microsoft.com> wrote in messagenews:26****************************@phx.gbl...
what is the error?
>-----Original Message-----
>Still learning ASP.NET....(and I was getting so good with
classic ASP too!).
>
>I'm trying to connect to a SQL Server using a simple

connection script.
>I've checked 2 different books and looked at
www.asp.net and still cannot
>get past this "error".
>
>Can anyone see the error? This <script> example is

almost line by line from
>the Sams ASP.NET Unleashed Book. The error is on line

8. Thanks.
>
>
>
>Compiler Error Message: BC30188: Declaration expected.
>
>Source Error:
>
>Line 8: DbConn = New SQLConnection("server=drpt-
server3; >database=DRPT-TEST")
>
>
>**********************************
>
><%@ Import Namespace="System.Data.SqlClient" %>
>
><script runat="server">
> Dim DbConn As SQLConnection
> Dim MySQLCommand As SQLCommand
> Dim RS As SQLDataReader
>
> DbConn = New SQLConnection("server=drpt-server3;

database=DRPT-TEST")
> DbConn.Open()
>
> MySQLCommand = New MySQLCommand("SELECT * FROM

Staff;", DbConn)
> RS = MySQLCommand.ExecuteReader()
></script>
>
><html xmlns="http://www.w3.org/1999/xhtml">
><head>
><title>Untitled Document</title>
></head>
><body>
><%
>RS.MoveFirst
>Response.Write RS("LastName").Value
>
>DbConn.Close()
>RS.Close()
> %>
></body>
></html>
>
>--
>
>
>*********************************
>D. Shane Fowlkes - TMM
>Saving the world, one web site at a time.
>http://www.shanefowlkes.com
>*********************************
>
>
>
>.
>

.

Nov 18 '05 #7

P: n/a
OK...So, why use <script> tags at all? Why not always use <% %>? Is there
really an advantage?

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************
"bruce barker" <no***********@safeco.com> wrote in message
news:uG**************@tk2msftngp13.phx.gbl...
unlike asp, only subroutines and functions are allowed in <script
runat=server> blocks. inline code is only allowed in with <% %>

-- bruce (sqlwork.com)

"D. Shane Fowlkes" <sh***@raccoonbob.com> wrote in message
news:O6**************@TK2MSFTNGP12.phx.gbl...
Still learning ASP.NET....(and I was getting so good with classic ASP

too!).

I'm trying to connect to a SQL Server using a simple connection script.
I've checked 2 different books and looked at www.asp.net and still cannot get past this "error".

Can anyone see the error? This <script> example is almost line by line

from
the Sams ASP.NET Unleashed Book. The error is on line 8. Thanks.

Compiler Error Message: BC30188: Declaration expected.

Source Error:

Line 8: DbConn = New SQLConnection("server=drpt-server3;
database=DRPT-TEST")
**********************************

<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Dim DbConn As SQLConnection
Dim MySQLCommand As SQLCommand
Dim RS As SQLDataReader

DbConn = New SQLConnection("server=drpt-server3; database=DRPT-TEST")
DbConn.Open()

MySQLCommand = New MySQLCommand("SELECT * FROM Staff;", DbConn)
RS = MySQLCommand.ExecuteReader()
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<%
RS.MoveFirst
Response.Write RS("LastName").Value

DbConn.Close()
RS.Close()
%>
</body>
</html>

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************


Nov 18 '05 #8

P: n/a
Here is what worked for me on a parameterized stored proc named
spExecuteGeneric which takes 2 parameters: @SQLQuery -A query (which is
deceptively named AuthorID) and ReturnVal, a returntype parameter Which
would hold an errror (I think). Hope this helps The biggest problem I had
was the connection string and "Trusted_Connection=False;" had to be declared
if I was using a login/pwd. You should probalby change that to true if using
trusted connection and leave off the UserName and PWD pairs

OK so I need to get uptodate on vbcrlf

Private Function fncRunSproc()
Dim MyDataSet As New DataSet("MyDataSet")
Dim AuthorID As SqlParameter
Dim ReturnVal As SqlParameter
Dim LoopCount As Integer
Dim NewString As New System.Text.StringBuilder
Dim RowCounter As Integer

Dim ConnStr As String = "Server=""ServerName"";workstation
id=""WORKSTATION_NAME"";packet size=4096;integrated security=SSPI;data
source=""SERVERNAME\DATABASENAME"";persist security info=False;initial
catalog=Pubs;Trusted_Connection=False;User
ID=""LoginName"";Password=""Password"""
Dim SQLConn As New SqlConnection(ConnStr)
Dim MySqlCmd As New SqlCommand("spExecuteGeneric", SQLConn)
MySqlCmd.CommandType = CommandType.StoredProcedure
'Dim SQLAdptr As New SqlDataAdapter(MySqlCmd)

txtResults.Text = ""
'txtResults.Refresh()

AuthorID = New SqlParameter
AuthorID.SqlDbType = SqlDbType.VarChar
AuthorID.ParameterName = "@SQLQuery"
AuthorID.Direction = ParameterDirection.Input
AuthorID.Value = txtQuery.Text
MySqlCmd.Parameters.Add(AuthorID)

ReturnVal = New SqlParameter '("RetValue", SqlDbType.Int)
ReturnVal.SqlDbType = SqlDbType.Int
ReturnVal.ParameterName = "RetValue"
ReturnVal.Direction = ParameterDirection.ReturnValue
MySqlCmd.Parameters.Add(ReturnVal)

SQLConn.Open()

Dim myReader As SqlDataReader
myReader = MySqlCmd.ExecuteReader()

NewString.Append(Chr(9))

For LoopCount = 0 To myReader.FieldCount - 1
NewString.Append(Trim(myReader.GetName(LoopCount). ToString) & Chr(9))
Next

NewString.Append(vbCrLf)

Do While myReader.Read
NewString.Append("(" & RowCounter & ")" & Chr(9))
RowCounter += 1
For LoopCount = 0 To myReader.FieldCount - 1
NewString.Append(Trim(myReader.GetSqlValue(LoopCou nt).ToString) &
Chr(9))
Next

NewString.Append(vbCrLf)
Loop

txtResults.Text &= NewString.ToString
myReader.Close()

txtResults.Text &= "Return Value: " & (ReturnVal.Value) & vbCrLf

SQLConn.Close()
End Function
"D. Shane Fowlkes" <sh***@raccoonbob.com> wrote in message
news:O6**************@TK2MSFTNGP12.phx.gbl...
Still learning ASP.NET....(and I was getting so good with classic ASP too!).
I'm trying to connect to a SQL Server using a simple connection script.
I've checked 2 different books and looked at www.asp.net and still cannot
get past this "error".

Can anyone see the error? This <script> example is almost line by line from the Sams ASP.NET Unleashed Book. The error is on line 8. Thanks.

Compiler Error Message: BC30188: Declaration expected.

Source Error:

Line 8: DbConn = New SQLConnection("server=drpt-server3;
database=DRPT-TEST")
**********************************

<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Dim DbConn As SQLConnection
Dim MySQLCommand As SQLCommand
Dim RS As SQLDataReader

DbConn = New SQLConnection("server=drpt-server3; database=DRPT-TEST")
DbConn.Open()

MySQLCommand = New MySQLCommand("SELECT * FROM Staff;", DbConn)
RS = MySQLCommand.ExecuteReader()
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<%
RS.MoveFirst
Response.Write RS("LastName").Value

DbConn.Close()
RS.Close()
%>
</body>
</html>

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************

Nov 18 '05 #9

P: n/a
Try ditching RS.MoveFirst and just using:

If RS.Read Then
Response.Write RS("LastName").Value
End If
"Anthony Williams" <to**@bigtone.net> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
Hmm...

Have you tried putting RS.Read after RS.MoveFirst?

Also, once you're getting good with DataReaders, you might want to consider ditching them in favour of DataSets. Much nicer.

Also - DON'T forget to DbConn.Dispose()
Regards,
Anth

"D. Shane Fowlkes" <sh***@raccoonbob.com> wrote in message
news:O6**************@TK2MSFTNGP12.phx.gbl...
Still learning ASP.NET....(and I was getting so good with classic ASP

too!).

I'm trying to connect to a SQL Server using a simple connection script.
I've checked 2 different books and looked at www.asp.net and still cannot get past this "error".

Can anyone see the error? This <script> example is almost line by line

from
the Sams ASP.NET Unleashed Book. The error is on line 8. Thanks.

Compiler Error Message: BC30188: Declaration expected.

Source Error:

Line 8: DbConn = New SQLConnection("server=drpt-server3;
database=DRPT-TEST")
**********************************

<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Dim DbConn As SQLConnection
Dim MySQLCommand As SQLCommand
Dim RS As SQLDataReader

DbConn = New SQLConnection("server=drpt-server3; database=DRPT-TEST")
DbConn.Open()

MySQLCommand = New MySQLCommand("SELECT * FROM Staff;", DbConn)
RS = MySQLCommand.ExecuteReader()
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<%
RS.MoveFirst
Response.Write RS("LastName").Value

DbConn.Close()
RS.Close()
%>
</body>
</html>

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************


Nov 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.