|
|
 |
| 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.
|
 |

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
|
|
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
|

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
|
|
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
|

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
|
|
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);
|

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
|
|
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
|

August 10th, 2007, 05:42 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

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
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |