Help with SQL

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 101
Reputation: Se7Olutionyg has a little shameless behaviour in the past 
Solved Threads: 0
Se7Olutionyg Se7Olutionyg is offline Offline
Junior Poster

Help with SQL

 
0
  #1
Oct 1st, 2009
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Xml.Linq;
  13.  
  14. namespace WebApplication5
  15. {
  16. public partial class _Default : System.Web.UI.Page
  17. {
  18. protected void Page_Load(object sender, EventArgs e)
  19. {
  20. SqlConnection conn = new SqlConnection(
  21. " Server =localhost\\SqlExpress; Database= Dorknozzle; " +
  22. "Integrated Secutiry = True" ) ;
  23.  
  24. SqlCommand comm = new SqlCommand(
  25. "SELECT EmployeeID, Name FROM Employees", conn);
  26. conn.Open();
  27. SqlDataReader reader = comm.ExecuteReader();
  28. reader.Close();
  29. conn.Close();
  30. while (reader.Read())
  31. {
  32. employeesLabel.Text += reader["Name"] + "<br/>";
  33. }
  34. reader.Close();
  35. conn.Close();
  36.  
  37. }
  38. }
  39. }

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication5._Default" %>
  2. <%@ Import Namespace = "System.Data.SqlClient" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">


how come it does not recgonized the SQL command while I have already imported ?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 433
Reputation: Ramesh S will become famous soon enough Ramesh S will become famous soon enough 
Solved Threads: 82
Ramesh S Ramesh S is offline Offline
Posting Pro in Training

Re: Help with SQL

 
0
  #2
Oct 1st, 2009
You need to import System.Data.SqlClient namespace in order to recognize the SqlConnection, SqlCommand and SqlDataReader etc objects.
Last edited by Ramesh S; Oct 1st, 2009 at 2:54 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 101
Reputation: Se7Olutionyg has a little shameless behaviour in the past 
Solved Threads: 0
Se7Olutionyg Se7Olutionyg is offline Offline
Junior Poster

Re: Help with SQL

 
-1
  #3
Oct 1st, 2009
i did it dude, you didn't see that ?
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,200
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Help with SQL

 
1
  #4
Oct 1st, 2009
You need to do it in your code behind file:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace WebApplication5
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(
                " Server =localhost\\SqlExpress; Database= Dorknozzle; " + 
                "Integrated Secutiry = True" ) ;

            SqlCommand comm = new SqlCommand(
                "SELECT EmployeeID, Name FROM Employees", conn);
            conn.Open();
            SqlDataReader reader = comm.ExecuteReader();
            reader.Close();
            conn.Close();
            while (reader.Read())
            {
                employeesLabel.Text += reader["Name"] + "<br/>";
            }
            reader.Close();
            conn.Close();

        }
    }
}
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 101
Reputation: Se7Olutionyg has a little shameless behaviour in the past 
Solved Threads: 0
Se7Olutionyg Se7Olutionyg is offline Offline
Junior Poster

Re: Help with SQL

 
0
  #5
Oct 3rd, 2009
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(
" Server =se7olutionyg-PC\\SqlExpress; Database= database1.mdf; " +
"Integrated Secutiry = True" ) ;

the program said that this part
SqlConnection conn = new SqlConnection(
" Server =se7olutionyg-PC\\SqlExpress; Database= database1.mdf; " +
"Integrated Secutiry = True" ) ;

the server should be local host or my server name ?
how about the name of database, Do i have to declare the directory to the database or it already included in the project ?
Why the integrated security is not available for my page ?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Help with SQL

 
1
  #6
Oct 5th, 2009
Originally Posted by Se7Olutionyg View Post
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace WebApplication5
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(
                " Server =localhost\\SqlExpress; Database= Dorknozzle; " + 
                "Integrated Secutiry = True" ) ;

            SqlCommand comm = new SqlCommand(
                "SELECT EmployeeID, Name FROM Employees", conn);
            conn.Open();
            SqlDataReader reader = comm.ExecuteReader();
            reader.Close();
            conn.Close();
            while (reader.Read())
            {
                employeesLabel.Text += reader["Name"] + "<br/>";
            }
            reader.Close();
            conn.Close();

        }
    }
}

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication5._Default" %>
  2. <%@ Import Namespace = "System.Data.SqlClient" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">


how come it does not recgonized the SQL command while I have already imported ?
You are closing your reader before you have read the data.
I put in bold what you should delete
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC