By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

VB to C# conversion ODBC

P: n/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.d ll"' %>
<%@ 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.d ll"' %>
<%@ 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.d ll"' %>
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

Nov 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"acb" <ch******@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
<%@ Import Namespace="Microsoft.Data.ODBC" %>
<script Language="C#" runat="server"> 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?)


Several things:

1) Are you still using v1.0 of the Framework? If not, you don't need the
ODBC add-in, as it's part of the v1.1 Framework. Use System.Data.Odbc
instead.

2) C# is case-sensitive - have you tried referencing 'Microsoft.Data.Odbc'
instead of 'Microsoft.Data.ODBC'?

3) Why are you writing your code "in-line" rather than in a separate
code-behind class...?
Nov 17 '05 #2

P: n/a
acb
Hi Mark,

Thanks for your reply and the suggestions. Comments inline.
Several things:

1) Are you still using v1.0 of the Framework? If not, you don't need the
ODBC add-in, as it's part of the v1.1 Framework. Use System.Data.Odbc
instead.
Although I did find reference to System.Data.Odbc while searching the
net, I never quite arrived to the point of realising that one was more
recent; also the example I found was based on the
'Microsoft.Data.Odbc'.


2) C# is case-sensitive - have you tried referencing 'Microsoft.Data.Odbc'
instead of 'Microsoft.Data.ODBC'?

No I don't think I did; I've already spent ours trying to sort out bugs
that end up being case related; must get a tatto: "C# is case
sensitive, C# is case sensitive, ..."
3) Why are you writing your code "in-line" rather than in a separate
code-behind class...?


I'm following the book "ASP.NET by Danny and Tommy Ryan". While I have
Visual Studio 2003 installed, the book (up to now) uses notepad to
generate code. I found the book to be quite instructive and to my
liking; this is the first problem I got stuck on (mainly because I
don't use MS SQL databased used in the book.

Again thanks for helping get on thr right track

Take Care
Chris

Nov 17 '05 #3

P: n/a
Mark,
3) Why are you writing your code "in-line" rather than in a separate
code-behind class...?


Probably because that sadly enough the Microsoft ASPNET team shows allmost
all their samples in that way, while the designer from the ASPNET team does
use that even more in the version 2.0 than it did in 1.x.

(By the way, I could only recognise that in the import description from
Read, in my opinion is he using code behind)

Cor
Nov 17 '05 #4

P: n/a
"acb" <ch******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
1) Are you still using v1.0 of the Framework? If not, you don't need the
ODBC add-in, as it's part of the v1.1 Framework. Use System.Data.Odbc
instead.
Although I did find reference to System.Data.Odbc while searching the
net, I never quite arrived to the point of realising that one was more
recent; also the example I found was based on the
'Microsoft.Data.Odbc'.


Well, fair enough, but it's important to realise that software moves on...
I've still got reference books which were written before even the first
version of .NET was released, but you can bet I'm not using them now...
No I don't think I did; I've already spent ours trying to sort out bugs
that end up being case related; must get a tatto: "C# is case
sensitive, C# is case sensitive, ..."


It's a well-known gotcha, especially for people (like me) coming from a VB
background....
3) Why are you writing your code "in-line" rather than in a separate
code-behind class...?


I'm following the book "ASP.NET by Danny and Tommy Ryan". While I have
Visual Studio 2003 installed, the book (up to now) uses notepad to
generate code. I found the book to be quite instructive and to my
liking; this is the first problem I got stuck on (mainly because I
don't use MS SQL databased used in the book.


I don't even know where to start with this...
Nov 17 '05 #5

P: n/a
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eD*************@TK2MSFTNGP10.phx.gbl...
Probably because that sadly enough the Microsoft ASPNET team shows allmost
all their samples in that way, while the designer from the ASPNET team
does use that even more in the version 2.0 than it did in 1.x.


Yes - I've never understood why they do that...
Nov 17 '05 #6

P: n/a
acb
Mark,
2) C# is case-sensitive - have you tried referencing 'Microsoft.Data.Odbc'
instead of 'Microsoft.Data.ODBC'?


For the record this ***was*** the problem.

Thank you for your answer.

I'm heading over to System.Data.Odbc land now; wish me luck :-)

Regards,
Chris

Nov 17 '05 #7

P: n/a
acb
The following is the upgraded solution which works:

%@ Page Language="C#" Debug="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.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>

Thanks again

Nov 17 '05 #8

P: n/a
"acb" <ch******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I'm heading over to System.Data.Odbc land now; wish me luck :-)


You won't need any luck - the object model is identical...
Nov 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.