Solved

New with Visual Studios 2005 - Importing

Posted on 2006-11-13
8
262 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now