Solved

New with Visual Studios 2005 - Importing

Posted on 2006-11-13
8
275 Views
Last Modified: 2008-01-09
I'm very new at Visual Studios and I would like to know how I can import my code below into Visual Studio and be able to debug (F5).

<%@ page language = "C#" %>
<%@ import namespace = "system.data.sqlclient" %>

<script runat= server>

void butoon_click (object sender, eventargs e) {
      SqlConnection conPubs;
      SqlCommand cmdSelect;
      SqlDataReader dtrResults;
      int intField;

      conPubs = new SqlConnection(Data Source=.\SQLExpress;Initial Catalog=myDB;Persist Security Info=True;User ID=sa;Password=xxxx;Connection Timeout=180");
      conPubs.Open ();
      cmdSelect = new SqlCommand (txtQurty.Text, conPubs);
      dtrResults = cmdSelect.ExecuteReader ();
      txtResults.Text = "";

      while (dtrResults.Read ()) {

            for (intField = 0; intField < dtrResults.FieldCount; intField++) {
                  txtResults.Text += dtrResults [intField].ToString().PadRight (15);
            }

      txtResults.Text += "\n";
      }

      dtrResults.close();
      conPubs.Close ();
}

</script>
<html>

Thanks

<form Runat= "Server">
<asp:TextBox
      id = "txtQuery"
      textMode = "Multiline"
      columns = "80"
      rows = "4"
      runat= "server" />
<br>
      <asp:button
      text = "Execute Query"
      onclick="Button_Click"
      runat = "server" />
<br>
      <asp:textbox
      id ="txtResults"
      txtMode="multiline"
      columns = "80"
      rows = "15"
      wrap = "false"
      readonly = "true"
      runat = "server" />

</forms>
</body>
</html>
0
Comment
Question by:adenosine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 11

Accepted Solution

by:
ethoths earned 25 total points
ID: 17930920
Not much! Add the pages and then fix the syntax errors. Remember C# is case sensitive. Here your page that I did earlier...

<%@ Page Language="C#" %>
<%@ import namespace = "System.Data.SqlClient" %>

<script runat= server>

void Button_Click (object sender, System.EventArgs e) {
     SqlConnection conPubs;
     SqlCommand cmdSelect;
     SqlDataReader dtrResults;
     int intField;

     conPubs = new SqlConnection(@"Data Source=.\SQLExpress;Initial Catalog=myDB;Persist Security Info=True;User ID=sa;Password=xxxx;Connection Timeout=180");
     conPubs.Open ();
     cmdSelect = new SqlCommand (txtQuery.Text, conPubs);
     dtrResults = cmdSelect.ExecuteReader ();
     txtResults.Text = "";

     while (dtrResults.Read ()) {

          for (intField = 0; intField < dtrResults.FieldCount; intField++) {
               txtResults.Text += dtrResults [intField].ToString().PadRight (15);
          }

     txtResults.Text += "\n";
     }

     dtrResults.Close();
     conPubs.Close ();
}

</script>
<html>
<body>
Thanks

<form id="Form1" Runat= "Server">
<asp:TextBox
     id = "txtQuery"
     textMode = "Multiline"
     columns = "80"
     rows = "4"
     runat= "server" />
<br>
     <asp:button
     text = "Execute Query"
     onclick="Button_Click"
     runat = "server"
     Id="Button" />
<br>
     <asp:textbox
     id ="txtResults"
     textMode="multiline"
     columns = "80"
     rows = "15"
     wrap = "false"
     readonly = "true"
     runat = "server" />

</form>
</body>
</html>


Of course it all depends on the code that you have but it's generally pretty simple.

PS Remeber to remove your user names and passowords from connection string prior to uploading to sites like this.


0
 

Author Comment

by:adenosine
ID: 17931357
How to add the pages?  I created a new solution and copy and paste this code into it and it didn't work.
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17931384
Probably best top add pages by creating a new page (right click the project and add new item) and then cutting and pasting the contents of the files. ASP.Net 2.0 does some new stuff when it comes to organising code files.

Please note though that I don't expect to code to work. You will have to edit it and correct the SYNTAX errors. I foud aboutr a dozen when I migrated the page above.

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:adenosine
ID: 17931541
<%@ page language = "C#" %>
<%@ import namespace = "system.data.sqlclient" %>

<script runat= server>

void butoon_click (object sender, eventargs e) {
      SqlConnection conPubs;
      SqlCommand cmdSelect;
      SqlDataReader dtrResults;
      int intField;

      conPubs = new SqlConnection(Data Source=.\SQLExpress;Initial Catalog=mydb;Persist Security Info=True;User ID=sa;Password=xxxx;Connection Timeout=180");
      conPubs.Open ();
      cmdSelect = new SqlCommand (txtQurty.Text, conPubs);
      dtrResults = cmdSelect.ExecuteReader ();
      txtResults.Text = "";

      while (dtrResults.Read ()) {

            for (intField = 0; intField < dtrResults.FieldCount; intField++) {
                  txtResults.Text += dtrResults [intField].ToString().PadRight (15);
            }

      txtResults.Text += "\n";
      }

      dtrResults.close();
      conPubs.Close ();
}

</script>
<html>
<head><title>test</title></head>
<body>
<form runat= "server">
<asp:TextBox
      id = "txtQuery"
      textMode = "multiline"
      columns = "80"
      rows = "4"
      runat= "server" />
<br/>
      <asp:button
      text = "Execute Query"
      onclick="Button_Click"
      runat = "server" />
<br/>
      <asp:textbox
      id ="txtResults"
      txtMode="multiline"
      columns = "80"
      rows = "15"
      wrap = "false"
      readonly = "true"
      runat = "server" />

</form>
</body>
</html>

I still get these errors.  I copy the code straight from a book so that I can test query statements and connection to the database.

Error      1      File 'server' was not found.      C:\Documents and Settings\452\My Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx      12      16      C:\...\WebSite1\
Error      2      Validation (XHTML 1.0 Transitional): Attribute values must be enclosed in quotation marks.      C:\Documents and Settings\452\My Documents\Visual Studio 2005\Projects\TestGCP\HTMLPage1.htm      4      16      Solution Items
Error      3      Validation (XHTML 1.0 Transitional): Element 'html' is missing required attribute 'xmlns'.      C:\Documents and Settings\452\My Documents\Visual Studio 2005\Projects\TestGCP\HTMLPage1.htm      32      2      Solution Items
Error      4      Validation (XHTML 1.0 Transitional): Element 'form' is missing required attribute 'action'.      C:\Documents and Settings\452\My Documents\Visual Studio 2005\Projects\TestGCP\HTMLPage1.htm      35      2      Solution Items
Error      5      Validation (XHTML 1.0 Transitional): This name contains uppercase characters, which is not allowed.      C:\Documents and Settings\452\My Documents\Visual Studio 2005\Projects\TestGCP\HTMLPage1.htm      38      2      Solution Items
Error      6      Unrecognized namespace 'asp'.      C:\Documents and Settings\452\My Documents\Visual Studio 2005\Projects\TestGCP\HTMLPage1.htm      36      2      Solution Items
Error      7      Unrecognized namespace 'asp'.      C:\Documents and Settings\452\My Documents\Visual Studio 2005\Projects\TestGCP\HTMLPage1.htm      43      3      Solution Items
Error      8      Validation (XHTML 1.0 Transitional): This name contains uppercase characters, which is not allowed.      C:\Documents and Settings\452\My Documents\Visual Studio 2005\Projects\TestGCP\HTMLPage1.htm      50      2      Solution Items
Error      9      Unrecognized namespace 'asp'.      C:\Documents and Settings\452\My Documents\Visual Studio 2005\Projects\TestGCP\HTMLPage1.htm      48      3      Solution Items
Error      10      There can be only one 'page' directive.      C:\Documents and Settings\452\My Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx      3      
Error      11      Program 'C:\Documents and Settings\452\My Documents\Visual Studio 2005\Projects\TestGCP\TestGCP\obj\Debug\TestGCP.exe' does not contain a static 'Main' method suitable for an entry point      TestGCP

0
 

Author Comment

by:adenosine
ID: 17931638
What concerts me is "server" not found?  And Unrecognize namespace?
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17931803
Have you crested your website in VS2005 by saying File > New Website...
0
 

Author Comment

by:adenosine
ID: 17932183
I think I import correctly the only error I get is the database connection.  Any clues?
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17936805
A good source for setting up connections strings is...

http://www.connectionstrings.com
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question