-
Import Statement
I am trying to use the Imports Statement as shown below, any idea why it keeps erroring out wit "declaration expected"
Thanks In Advance
Import Namespace="System.Data"
Import Namespace="System.Data.SqlClient"
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
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
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
End Sub
End Class
-
Imports System.Data
Imports System.Data.Sqlclient
-
very impressive, any chance u could help me with the code problem?
-
what is the code problem?
-
I am trying to use the Imports Statement as shown below, any idea why it keeps erroring out with "declaration expected" error
Import Namespace="System.Data"
Import Namespace="System.Data.SqlClient"
Public Class WebForm1
Inherits System.Web.UI.Page
Can i not use imports when working with web forms?
Thanks
-
dude...i just told you the answer
Imports System.Data
Imports System.Data.Sqlclient
you are using it wrong...the Imports statement you are using is for in .aspx pages..you are using a code behind page so you do it like I showed you above.
-
Thanks, im feeling rather vacant today.
-
simple mistake...I often get C# and VB .NET mixed up and use 'Imports' in C# and 'using' in VB... using is the C# version of Imports..
:p
-
Thanks Cander
Maybe u can help me with another problem.
I am just testing my very first datagrid with little result. When i run the aspx page i get an empty page? the code is below see if can suss out why, i can't?
thanks!
-----asp.net code----------
Imports System.Data.OleDb
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
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
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New OleDbConnection("c:\helpdesk.mdb")
Dim cmd As OleDbCommand
con.Open()
cmd = New OleDbCommand("Select * from faults", con)
DataGrid1.dataSource = cmd.ExecuteReader()
DataGrid1.DataBind()
con.Close()
End Sub
End Class
---------HTML code----------
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="aspnet.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<aspataGrid id="DataGrid1" runat="server" style="Z-INDEX: 101; LEFT: 46px; POSITION: absolute; TOP: 48px" runat="server" Width="532px" Height="186px"></aspataGrid>
</form>
</body>
</HTML>
-
hmm..look correct except that I beleive that on this line
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="aspnet.WebForm1"%>
codebehind should say src...(I think) and the Inherits should just say WebForm1..not aspnet.WebForm1
????
Try that..
other than that...it dont see any problems.
-
I do see one problem
<aspataGrid
now does it look like that in your code?
It maybe that you have smiles psoting turned of when you posted this si it stripped out : and D
it should say
asp:datagrid
i did a lower case d so the smilie wouldnt show up.
anyway...make sure that your actual code is not missing that although i doubt it.
-
its does say asp:DataGrid i also tried the other changes, but the result was the same i.e. a blank web page with no data. Is there something wrong with the way im conencting maybe?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New OleDbConnection("c:\helpdesk.mdb")
Dim cmd As OleDbCommand
con.Open()
cmd = New OleDbCommand("Select * from faults", con)
DataGrid1.dataSource = cmd.ExecuteReader()
DataGrid1.DataBind()
con.Close()
End Sub
-
I dont think so..if there was a problem with the connection, you would get an error I would think..hmmm
try using datasets and dataadapter istead of
dbcommand
Dim myDS As New DataSet
Dim myCommand As OleDbDataAdapter
myCommand = New OleDbDataAdapter("Select * from faults", con)
' Fill the DataSet and name the table
myCommand.Fill(myDS, "faults")
MyDataGrid.DataSource = myDS.Tables("faults").DefaultView
MyDataGrid.DataBind()
see if that works..
-
Cander, like u said there doesn't seem to be a problem with the code - what other reasons could there be for the datagrid to not be displayed at all. Would the datagrid be displayed if there was no data?
Dean
-
I would think that the table columns would show..
-
Infact i added some other components and then tried it, but nothing will show at all, hmm im confused.
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="src..." Inherits="WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server" style="Z-INDEX: 101; LEFT: 46px; POSITION: absolute; TOP: 48px" Width="532px" Height="186px" BackColor="#C0FFC0" BorderColor="Aqua" ForeColor="Blue" DESIGNTIMEDRAGDROP="72" BorderStyle="Dotted"></asp:DataGrid>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 31px; POSITION: absolute; TOP: 18px" runat="server" Width="116px" Text="Button"></asp:Button>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 103; LEFT: 18px; POSITION: absolute; TOP: 113px" runat="server" Width="20px" Height="103px"></asp:DropDownList>
</form>
</body>
</HTML>
-
problem..here you have
Codebehind="src..."
that not what I meant when I said change codebehind to src :P
what i mean was replace the word CodeBehind with Src and put the codebehind path back like it was
:p
Try that.
See if it makes any difference
-
the saga contines...
Hi Cander, i tried src still no change i also bound the datagrid to the page but still nothing is displayed?
-
d'oh...ill keep looking into it
-
Hi Cander,
I re-installed iis & .net now i can see components, although i am getting error as shown below
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Format of the initialization string does not conform to the OLE DB specification. Starting around char[0] in the connection string.
Source Error:
Line 25: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Line 26:
Line 27: Dim con As New OleDbConnection("c:\helpdesk.mdb")
Line 28: Dim myDS As New DataSet()
Line 29: Dim myCommand As OleDbDataAdapter
Source File: c:\inetpub\wwwroot\WebApplication2\WebForm1.aspx.vb Line: 27
-
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=c:\whatever.mdb")
-
im not getting this error. Maybe u can see the problem?
An invalid data source is being used for DataGrid1. A valid data source must implement either IListSource or IEnumerable.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: An invalid data source is being used for DataGrid1. A valid data source must implement either IListSource or IEnumerable.
Source Error:
Line 35:
Line 36: DataGrid1.DataSource = myDS.Tables("faults").DefaultView
Line 37: DataGrid1.DataBind()
Line 38:
Line 39: End Sub
-
Erm... you might want to try to build your application before running the program if you don't use src and use a codebehind argument instead. That might help for VS.NET users (me)