Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 10th, 2007, 01:16 AM
Authorized User
 
Join Date: Jul 2007
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


 
Old August 10th, 2007, 01:41 AM
Registered User
 
Join Date: Aug 2007
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
 
Old August 10th, 2007, 01:47 AM
Authorized User
 
Join Date: Jul 2007
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);

 
Old August 10th, 2007, 02:17 AM
Registered User
 
Join Date: Aug 2007
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
 
Old August 10th, 2007, 04:42 AM
Friend of Wrox
 
Join Date: Feb 2006
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
 
Old August 10th, 2007, 05:24 AM
Authorized User
 
Join Date: Jul 2007
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.






Similar Threads
Thread Thread Starter Forum Replies Last Post
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 07: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.