Solved

New with Visual Studios 2005 - Importing

Posted on 2006-11-13
8
268 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 

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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
jQuery - following an example but can I save data server side? 20 58
Footer for each row on Gridview 2 32
Linq asp.net mvc 13 17
ASP.NET Content Page 3 27
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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