Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 14th, 2007, 09:37 PM
Registered User
 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Syntax error? <%@ Import Namespace="System.Data" %

hi, could someone please help --------

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="C#" runat="server">
    void Page_Load(Object sender, EventArgs e)
    {
        OleDbConnection objConnection;
        OleDbConnection objCommand;
        string strConnect;
        string strCommand;
        DataSet DataSet1 = new DataSet();

        strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;";

        //If you don't have the grocertogo.mdb database then
        //you will have to change the following three lines

        strConnect += @"Data Source=C:\program files\microsoft.net\FrameworkSDK\";
        strConnect += @"Samples\quickstart\assplus\samples\grocertogo\da ta";
        strConnect += @"\grocertogo.mdb;";

        strConnect += "Persist Security Info=False";

        strCommand = "SELECT ProductName, UnitPrice FROM Products";
        objConnection = new OleDbConnection(strConnect);
        objCommand = new OleDbDataAdapter(strCommand, objConnection);
        objCommand.Fill(DataSet1, "products");
        DataGrid1.DataSource=DataSet1.Tables["Products"].DefaultView;
        DataGrid1.DataBind();

    }
    </script>
    <html>
    <head>
    <title>Data Grid Control example</title>
    </head>
    <body>
    <asp:DataGrid ID="DataGrid1" runat="server" />
    </body>
    </html>


---------------

and i am getting this 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: CS0029: Cannot implicitly convert type 'System.Data.OleDb.OleDbDataAdapter' to 'System.Data.OleDb.OleDbConnection'

Source Error:



Line 23: strCommand = "SELECT ProductName, UnitPrice FROM Products";
Line 24: objConnection = new OleDbConnection(strConnect);
Line 25: objCommand = new OleDbDataAdapter(strCommand, objConnection);
Line 26: objCommand.Fill(DataSet1, "products");
Line 27: DataGrid1.DataSource=DataSet1.Tables["Products"].DefaultView;


-----------


also, a squigley line is under <%@ Namespace="System.Data" %> - and when hovering over it it says - "syntax error"

any help would be much appreciated,

sincerely

 
Old January 16th, 2007, 09:17 AM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please Check your Code.
Plz do following change.

-- Instead of OleDbConnection objCommand;
write OleDBDataAdapter objCommand for the second initalization statement.





Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax error?<%@ Import Namespace="System.Data" %> fjm9 ASP.NET 1.0 and 1.1 Basics 2 January 16th, 2007 11:51 AM
Import Namespace seannie ASP.NET 2.0 Basics 0 December 7th, 2006 04:48 AM
aspx.vb import system.data.oracleclient nutrino ASP.NET 2.0 Basics 1 May 5th, 2006 07:56 AM
Error import namespace sersanoi Classic ASP Databases 0 August 18th, 2005 12:10 PM
ASP.net page can't find namespace system.data.orac mel ASP.NET 1.0 and 1.1 Basics 6 December 2nd, 2004 05:24 PM





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