locked
Migrating from VB to C# and database not working RRS feed

  • Question

  • User-1032411480 posted

     I've got a real complicated (for me, anyway) problem.

    I have an Access database on my current site. I have results pages that are .aspx pages with VB code. Everything works fine.

    But the site is being upgraded, and with the new .aspx pages the default page code is C#, not VB. On our development site (same machine, different directory, and from what I can see in the site settings the same database connections are present and valid in that development directory) I have copied over the "fpdb" folder and the database as well as the _fpclass folder (I had to rename the folder without the "_" but my .aspx page seems to be finding the folder and its files just fine). Of course, I have "fpdblib.inc", "fpdbrgn1.inc" and "fpdgrgn2.inc" as includes on my results .aspx page just like on the original site, but since they are in VB, my new C# .aspx page is throwing errors. So I tried using "<script type="text/VB"></script> tags around the code of the 3 files instead of the default "<% %>", and the errors stop, but I get no results from my database when a query is passed (though when I view the source I can see the code has been included), and when I use the runat="server" directive I get errors again (I assume it's not supposed to run at the server though?). I even tried converting the 3 .inc files to C# with the help of an online converter and I still got errors. And also, on the .aspx results page itself, there is additional "<% %>" code for the field values in the database results region that I think I need to convert as well.

    I'm at a loss of what I should do. If there are working C# versions of the .inc files out there that might be exactly what I need, as well as knowing what code to use for the field values of the database results region as mentioned. The only other thing I can think of is doing without the FP database code and using just all SQL and whatever else I need to handle the results page (whatever the .inc files are doing), but that's all going to be new to me and I'm under pressure as it is with migrating the rest of the Web site. I was hoping eventually to work on migrating the databases from Access to SQL/MYSQL or whatever, but I wanted time to do it right and now is just the worst time...

    Anyone have any insight or answers they can share with me? The best solution for me (and my sanity) at the moment would be to find a way to keep what I have and just make it work with the new C# pages (which are full of other features that are all C#, so reverting to VB as the default code is not an option).

    Thanks...

    Saturday, April 11, 2009 12:56 PM

Answers

  • User-821857111 posted

    The "quickest" way is to rewrite the page.  You can ignore the "inc" files.  They have no place in ASP.NET.  Connecting to an Access database is ASP.NET is straightforward: http://www.mikesdotnetting.com/Article.aspx?ArticleID=78

    Here's some other Access-related articles that might help you on your way: http://www.mikesdotnetting.com/Category.aspx?Category=10

    By the way, classic ASP is written using scripting languages like VBScript or Javascript.  ASP.NET is written using static strongly typed languages like C# or VB.Net.  Your original site doesn't use VB.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 12, 2009 2:15 AM
  • User-821857111 posted

    You can still pass the starts with keyword, end with keyword etc values as a session variable, then you would set up SQL as above, but syntactically correct:

    "SELECT * FROM DatabaseInfoEntry WHERE (Description LIKE '%' + @keyword + '%' OR [Database name] LIKE '%' + @keyword + '%' OR Subject LIKE '%' + @keyword + '%' ) ORDER BY [Database name]"

    The above version is for "contains".  The % signs are wildcards.  The @keyword is a parameter marker.  More information can be found here: http://www.mikesdotnetting.com/Article.aspx?ArticleID=26

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 15, 2009 4:07 PM

All replies

  • User-821857111 posted

    It sounds to me like you are trying to convert a classic ASP (VBScript - pages end in .asp) site to ASP.NET C#.  These are two completely different technologies.  Just putting .aspx on the file name and hoping it will run won't work.  Otherwise there is absolutely no good reason for changing ASP.NET pages written in VB to C#.  New ones can be written in C#.  They will run together.

    If I have got the wrong end of the stick, post some of the errors and the code that causes them.

     

     

    Saturday, April 11, 2009 5:12 PM
  • User-1032411480 posted

     Hi Mike, thank you very much for your reply!

    As it turns out, you are mostly correct in your assumption. *Most* of the old site is using classic ASP, including the results pages. However the actual database search page is a .NET (aspx) page since I had to upgrade it at one point to enable a TreeView menu system on it (not that the difference in that case has much bearing on my problem anyway). So I have an aspx search page with an asp results page. But the new site is going to be entirely aspx (with code-behinds) with C# as the default language, and I have a number of features (e.g. components of the Obout.com suite, a style/theme-switcher, etc) working with it.

    On the original asp results page I had used FrontPage extensions to create a connection to my Access database, which by default added "includes" for the 3 aforementioned "inc" files in the results region, which are all VB (or is it VBScript? Is that where I'm getting confused? I thought they were just VB though, since the original site is set to use VB as the default language).  Anyway, those inc files are encased in asp code tags (<% %>) and work properly on the old page, but trying that on the new page just throws a ton of errors since it's assuming my code is supposed to be C# in the inc files, which it isn't. I'd post more specific errors for you right now but unfortunately I'm not posting this from my work computer so I'd have to wait until Monday to do so...

     

    I guess maybe I should streamline my original question: what is the best/easiest way to update a database results asp page that uses FrontPage data extensions (and the inc files) to an aspx C# page in a minimum amount of time?

    Saturday, April 11, 2009 6:50 PM
  • User-821857111 posted

    The "quickest" way is to rewrite the page.  You can ignore the "inc" files.  They have no place in ASP.NET.  Connecting to an Access database is ASP.NET is straightforward: http://www.mikesdotnetting.com/Article.aspx?ArticleID=78

    Here's some other Access-related articles that might help you on your way: http://www.mikesdotnetting.com/Category.aspx?Category=10

    By the way, classic ASP is written using scripting languages like VBScript or Javascript.  ASP.NET is written using static strongly typed languages like C# or VB.Net.  Your original site doesn't use VB.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 12, 2009 2:15 AM
  • User-1032411480 posted

     Thank you very much Mike! I'm going to give that a try.  [cool]

    Sunday, April 12, 2009 9:30 AM
  • User-1032411480 posted

     Okay, I'm trying to set up a database connection (via SqlDataSource) but for some reason the path to the database insists on being a local cached copy of the database on my machine instead of on our development server, "C:\Documents and Settings\user\Local Settings\Temporary Internet Files\Content.IE5\ZR2XSWD7\GLdatabasesNew[3].mdb". I'm browsing to the location on our server via "My Network Places".

    I'm connecting to our development server with VWD Express. I've tried using the "|DataDirectory|databasename.mdb" format for the path, but it won't take that. I know I'm missing something elementary here, but this kind of database connection is new to me.  Any suggestions?

     

    EDIT!!!:  Whoops, okay, I discovered that the connection wizard is/was my problem here. I manually entered the code into my web.config file (bypassing the wizard entirely) and I've got it working at the most basic level with a Gridview control.

     

    However, maybe you can give me an idea of how I would duplicate something like the following code which was working on my old page to do the same thing in asp.net (with a minimum of extra coding?):

     

     

    <% 
    If Session("Select1") = "contains this keyword" Then
    fp_sQry="SELECT * FROM DatabaseInfoEntry WHERE (Description LIKE '%::keyword::%' OR [Database name] LIKE '%::keyword::%' OR Subject LIKE '%::keyword::%') ORDER BY [Database name]"
    fp_sDefault="%keyword%=&%keyword%=&%keyword%=&%keyword%="


    elseif Session("Select1") = "exactly this keyword" Then
    fp_sQry="SELECT * FROM DatabaseInfoEntry WHERE (Description LIKE '::keyword::' OR [Database name] LIKE '::keyword::' OR Subject LIKE '::keyword::') ORDER BY [Database name]"
    fp_sDefault="keyword=&keyword=&keyword=&keyword="


    elseif Session("Select1") = "starts with this keyword" Then
    fp_sQry="SELECT * FROM DatabaseInfoEntry WHERE (Description LIKE '::keyword::%' OR [Database name] LIKE '::keyword::%' OR Subject LIKE '::keyword::%') ORDER BY [Database name]"
    fp_sDefault="keyword%=&keyword%=&keyword%=&keyword%="


    elseif Session("Select1") = "ends with this keyword" Then
    fp_sQry="SELECT * FROM DatabaseInfoEntry WHERE (Description LIKE '%::keyword::' OR [Database name] LIKE '%::keyword::' OR Subject LIKE '%::keyword::') ORDER BY [Database name]"
    fp_sDefault="%keyword=&%keyword=&%keyword=&%keyword="


    End If

    %>
      Thanks again Mike!
    Tuesday, April 14, 2009 4:17 PM
  • User-1032411480 posted

     *bump?*

    Wednesday, April 15, 2009 11:24 AM
  • User-821857111 posted

    You can still pass the starts with keyword, end with keyword etc values as a session variable, then you would set up SQL as above, but syntactically correct:

    "SELECT * FROM DatabaseInfoEntry WHERE (Description LIKE '%' + @keyword + '%' OR [Database name] LIKE '%' + @keyword + '%' OR Subject LIKE '%' + @keyword + '%' ) ORDER BY [Database name]"

    The above version is for "contains".  The % signs are wildcards.  The @keyword is a parameter marker.  More information can be found here: http://www.mikesdotnetting.com/Article.aspx?ArticleID=26

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 15, 2009 4:07 PM
  • User-1032411480 posted

     Awesome, thanks Mike! You've helped me out a lot.

    I've decided to bind my SQLDataSource to a ListView so I can style the individual items (and avoid table formatting), and I've added a DataPager above and below. So far it's working quite well.  The only part that's really slowing me down is trying to re-write all the VBScript code that I had for various functions into C# onto the code-behind page. I'm still learning C# and most of the VBScript was borrowed from elsewhere, so it's slow going. I even took a look at Microsoft's ASP to ASP.NET migration assistant, but it doesn't appear to work with VWD Express and seems to be mostly unused anyway since it never got past .NET 1.1.

     Do you know of any related controls that do things like keyword highlighting, search logic (like the code above, but better than mine?), etc?

     

    Thanks again.

     

    Wednesday, April 15, 2009 5:51 PM
  • User-821857111 posted

    Do you know of any related controls that do things like keyword highlighting, search logic (like the code above, but better than mine?), etc?
     

    No I don't.

    The only part that's really slowing me down is trying to re-write all the VBScript code that I had for various functions into C# onto the code-behind page. I'm still learning C# and most of the VBScript was borrowed from elsewhere, so it's slow going.
     

    It will get much quicker as you go.

     

    Thursday, April 16, 2009 2:32 AM
  • User-1032411480 posted

     Okay, things are going pretty well with the conversion, but I've hit a snag with some embedded preprocessor commands for my listview item template. The following code gives me an "CS1040: Preprocessor directives must appear as the first non-whitespace character on a line" error:

     

    <p class="dbresults">Link:</p><asp:HyperLink ID="HyperLink1" runat="server" CssClass="dbresults" NavigateUrl='<%# Eval("Link")%>'><%=findStringLocation( <%# Eval("Database name")%>),Request["keyword"],"yellow")%></asp:HyperLink><br />

     

    I'm Googling around for syntax of embeded preprocessor commands but I'm having no luck here...  Thanks.

    Friday, April 17, 2009 2:56 PM
  • User-821857111 posted

    This is where you should really start a new thread for each problem you cannot resolve yourself.  The reason for that is that this thread is now marked as resolved, and a lot of members will therefore ignore it.

    When you post, explain what the findStringLocation() function does, or what you intend it to do.

     

    Friday, April 17, 2009 3:13 PM
  • User-1032411480 posted

     I'll do that.

    Friday, April 17, 2009 3:35 PM