?
Solved

New with Visual Studios 2005 - Importing

Posted on 2006-11-13
8
Medium Priority
?
278 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 100 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

770 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