A
acb
Hello,
I am a beginner in ASP.NET and C# having programmed in VB (not the .NET
flavour) in the past. I am looking for assistance in converting a
functional VB.NET aspx page to C#.
I am trying to extract data from a database using ODBC. A search on the
internet led me to the page at
http://forums.asp.net/27667/ShowPost.aspx that contained a functional
example in VB.NET. This worked on my computer. Hereunder is a snippet
of the code that can be used to demonstrate the problem:
<%@ Page Language="VB" Debug="True" CompilerOptions='/R:"C:\Program
Files\Microsoft.NET\Odbc.Net\Microsoft.Data.Odbc.dll"' %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Microsoft.Data.ODBC" %>
<script Language="VB" runat="server">
'DATABASE CONNECTION
Dim strConn As String = "DSN=Cache"
Public Sub Page_Load (obj As Object, e As EventArgs)
'DISPLAY RECORDS IN DATAGRID WHEN PAGE FIRST LOADS
End Sub
</script>
<html>
<head>
</head>
<body>
<asp:datagrid id="MyDataGrid" runat="server" />
</body>
</html>
My conversion of the above to C# is the following:
<%@ Page Language="C#" Debug="True" CompilerOptions='/R:"C:\Program
Files\Microsoft.NET\Odbc.Net\Microsoft.Data.Odbc.dll"' %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Microsoft.Data.ODBC" %>
<script Language="C#" runat="server">
// DATABASE CONNECTION
string strConn = "DSN=Cache";
void Page_Load (Object obj, EventArgs e)
{
// DISPLAY RECORDS IN DATAGRID WHEN PAGE FIRST LOADS
}
</script>
<html>
<head>
</head>
<body>
<asp:datagrid id="MyDataGrid" runat="server" />
</body>
</html>
My problem is that during compilation I keep getting the following
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: CS0234: The type or namespace name 'ODBC' does
not exist in the class or namespace 'Microsoft.Data' (are you missing
an assembly reference?)
Source Error:
Line 1: <%@ Page Language="C#" Debug="True"
CompilerOptions='/R:"C:\Program
Files\Microsoft.NET\Odbc.Net\Microsoft.Data.Odbc.dll"' %>
Line 2: <%@ Import Namespace="System.Data" %>
Line 3: <%@ Import Namespace="Microsoft.Data.ODBC" %> <<--- Problem
line
Line 4: <script Language="C#" runat="server">
Line 5:
Can someone please help me.
Thank You
Chris
I am a beginner in ASP.NET and C# having programmed in VB (not the .NET
flavour) in the past. I am looking for assistance in converting a
functional VB.NET aspx page to C#.
I am trying to extract data from a database using ODBC. A search on the
internet led me to the page at
http://forums.asp.net/27667/ShowPost.aspx that contained a functional
example in VB.NET. This worked on my computer. Hereunder is a snippet
of the code that can be used to demonstrate the problem:
<%@ Page Language="VB" Debug="True" CompilerOptions='/R:"C:\Program
Files\Microsoft.NET\Odbc.Net\Microsoft.Data.Odbc.dll"' %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Microsoft.Data.ODBC" %>
<script Language="VB" runat="server">
'DATABASE CONNECTION
Dim strConn As String = "DSN=Cache"
Public Sub Page_Load (obj As Object, e As EventArgs)
'DISPLAY RECORDS IN DATAGRID WHEN PAGE FIRST LOADS
End Sub
</script>
<html>
<head>
</head>
<body>
<asp:datagrid id="MyDataGrid" runat="server" />
</body>
</html>
My conversion of the above to C# is the following:
<%@ Page Language="C#" Debug="True" CompilerOptions='/R:"C:\Program
Files\Microsoft.NET\Odbc.Net\Microsoft.Data.Odbc.dll"' %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Microsoft.Data.ODBC" %>
<script Language="C#" runat="server">
// DATABASE CONNECTION
string strConn = "DSN=Cache";
void Page_Load (Object obj, EventArgs e)
{
// DISPLAY RECORDS IN DATAGRID WHEN PAGE FIRST LOADS
}
</script>
<html>
<head>
</head>
<body>
<asp:datagrid id="MyDataGrid" runat="server" />
</body>
</html>
My problem is that during compilation I keep getting the following
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: CS0234: The type or namespace name 'ODBC' does
not exist in the class or namespace 'Microsoft.Data' (are you missing
an assembly reference?)
Source Error:
Line 1: <%@ Page Language="C#" Debug="True"
CompilerOptions='/R:"C:\Program
Files\Microsoft.NET\Odbc.Net\Microsoft.Data.Odbc.dll"' %>
Line 2: <%@ Import Namespace="System.Data" %>
Line 3: <%@ Import Namespace="Microsoft.Data.ODBC" %> <<--- Problem
line
Line 4: <script Language="C#" runat="server">
Line 5:
Can someone please help me.
Thank You
Chris