Results 1 to 23 of 23

Thread: Import Statement

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    67

    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

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Imports System.Data
    Imports System.Data.Sqlclient
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    67
    very impressive, any chance u could help me with the code problem?

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    what is the code problem?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    67
    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

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    67
    Thanks, im feeling rather vacant today.

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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..

    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    67
    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>

  10. #10
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  11. #11
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    67
    its does say aspataGrid 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

  13. #13
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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..
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    67
    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

  15. #15
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    I would think that the table columns would show..
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    67
    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">
    <aspataGrid 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"></aspataGrid>
    <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 31px; POSITION: absolute; TOP: 18px" runat="server" Width="116px" Text="Button"></asp:Button>
    <aspropDownList id="DropDownList1" style="Z-INDEX: 103; LEFT: 18px; POSITION: absolute; TOP: 113px" runat="server" Width="20px" Height="103px"></aspropDownList>
    </form>
    </body>
    </HTML>

  17. #17
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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



    Try that.
    See if it makes any difference
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    67

    the saga contines...

    Hi Cander, i tried src still no change i also bound the datagrid to the page but still nothing is displayed?

  19. #19
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    d'oh...ill keep looking into it
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    67
    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

  21. #21
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=c:\whatever.mdb")
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    67
    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

  23. #23
    Lively Member
    Join Date
    Feb 2001
    Location
    KL Malaysia
    Posts
    64
    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width