p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 10th, 2007, 02:16 AM
Authorized User
 
Join Date: Jul 2007
Location: gurgaon, haryana, India.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default show data record in grid view - sqlserver2005

I am using asp.net 2.0 and sqlserver experess 2005.
ihad created a data base and a table in it.
i want to show its record in gridview on clicking a button.
i had write this code in my aspx.cs file


using System.Data.SqlClient;


public partial class data : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Server=localhost;Database=vinod;uid =sa;pwd=papa;");

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        string s = "select * from emp";
        SqlDataAdapter adp = new SqlDataAdapter(s, con);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
}


when i build this page it succeeded but when i run this page and click the button to show the data in gridview it shows error in my aspx.cs fil.


PLZ help me to solve this problem


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old August 10th, 2007, 02:41 AM
Registered User
 
Join Date: Aug 2007
Location: hyderabad, a.p, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi
in this u didn't take the sqlcommand .
u put the below code and check

        string s = "select * from emp";
        SqlCommand cmd = new SqlCommand(s,con);
        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();

gudluck
Kiranmai

Archu
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old August 10th, 2007, 02:47 AM
Authorized User
 
Join Date: Jul 2007
Location: gurgaon, haryana, India.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for reply,
but it has the same error as it was giving earlier,

and the error is

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

 on line adp.fill(ds);

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old August 10th, 2007, 03:17 AM
Registered User
 
Join Date: Aug 2007
Location: hyderabad, a.p, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sry
Even i'm also getting the same error in one of my application
if u get the solution then plz forward it to me also
thank u in advance
Kiranami

Archu
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old August 10th, 2007, 05:42 AM
Friend of Wrox
Points: 512, Level: 8
Points: 512, Level: 8 Points: 512, Level: 8 Points: 512, Level: 8
Activity: 5%
Activity: 5% Activity: 5% Activity: 5%
 
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

Check your connectionstring. It may be incorrect.
Try this connectionstring:
SqlConnection con = new SqlConnection("Server=localhost;Database=vinod;uid =sa;pwd=;");
                   Or,
SqlConnection con = new SqlConnection("Server=FullDatabaseName;Database=vi nod;uid=sa;pwd=papa;");

Gaurav
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old August 10th, 2007, 06:24 AM
Authorized User
 
Join Date: Jul 2007
Location: gurgaon, haryana, India.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Gaurav,

but i solved this problem using
SqlConnection con = new SqlConnection("server=localhost;database=vinod;Integrated Security=True");
 and set sql server on windows authentication mode.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Grid View Control tbreslin BOOK: Professional VB 2005 with .NET 3.0 ISBN: 978-0-470-12470-3 1 August 10th, 2009 05:47 AM
Paging Data grid view Prakash001 Visual Basic 2005 Basics 0 February 6th, 2008 04:07 AM
How to display data into Grid View? Somesh ASP.NET 2.0 Professional 5 May 25th, 2007 08:07 AM
Data Grid View CoolDude C# 2005 3 March 10th, 2007 05:37 AM
Show data in tree-view structure kiennt Crystal Reports 1 March 1st, 2004 06:21 PM



All times are GMT -4. The time now is 12:12 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc