• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

New with Visual Studios 2005 - Importing

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
adenosine
Asked:
adenosine
  • 4
  • 4
1 Solution
 
ethothsCommented:
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
 
adenosineAuthor Commented:
How to add the pages?  I created a new solution and copy and paste this code into it and it didn't work.
0
 
ethothsCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
adenosineAuthor Commented:
<%@ 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
 
adenosineAuthor Commented:
What concerts me is "server" not found?  And Unrecognize namespace?
0
 
ethothsCommented:
Have you crested your website in VS2005 by saying File > New Website...
0
 
adenosineAuthor Commented:
I think I import correctly the only error I get is the database connection.  Any clues?
0
 
ethothsCommented:
A good source for setting up connections strings is...

http://www.connectionstrings.com
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now