SQLconnection?

S

Sam

I want to connect sql database via ado.net but error is encounter as shown
as below:


Compilation Error
=================
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30188: Declaration expected.

Source Error:
=============
Line 7: Dim myCommand As SqlCommand = New SqlCommand("select * from
gldate", myConnection)
Line 8:
Line 9: myConnection.Open()
Line 10:
Line 11:



Show Detailed Compiler Output:
==============================
myConnection.Open()
~~~~~~~~~~~~
D:\SQLDB\Intranet\WebApp\Finance\subsystem\gl\dropdownlist.aspx(15) : error
BC30188: Declaration expected.

myConnection.Close()
~~~~~~~~~~~~


find.aspx
=========
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">

Dim myConnection As SqlConnection = New
SqlConnection("server=(sql01);database=ERP_ARCHIVAL;user
id=intranet;password=intranet")
Dim myCommand As SqlCommand = New SqlCommand("select * from gldate",
myConnection)

myConnection.Open()


Dim dr As SqlDataReader = myCommand.ExecuteReader()


myConnection.Close()

</script>
<html>
<head>
<title>Intranet Information System</title>
</head>
<body>
<form runat="server">
<asp:DropDownList id="DropDownList1"
runat="server"></asp:DropDownList>
</form>
</body>
</html>


Please help.
 
M

Miha Markic [MVP C#]

Sounds to me like you've never declared myConnection variable (althoug there
i see the declaration).
Try commenting all the code and then uncomment line by line and see what
happens.
 
C

Cor Ligthert

Sam,

You can try with setting an try block in your code.

Something as
Try
connection.open
Catch ex as exception
response.redirect(ex.tostring)
End try

Mostly you get than more information.

I hope this helps.

Cor
 
E

Elton Wang

You may need to use Imports rather than Import in

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

HTH

Elton Wang
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top