Click here to Skip to main content
15,888,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Why this code is not running ? This is Showing error in con.Open();
ASP.NET
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>
<%@Page Language="C#" Debug="true" %>
<script  runat="server" language="c#">
void Page_Load(object sender,EventArgs e)
{
if (!IsPostBack)
{
BindGridview();
}
}
void BindGridview()
{
SqlConnection con = new SqlConnection("Data Source=JDPANDEY-PC;Integrated Security=true;Initial Catalog=GridViewTesting");
con.Open();
SqlCommand cmd = new SqlCommand("select * from User", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Close();        
DataSet ds = new DataSet();
da.Fill(ds);
gvrecords.DataSource = ds;
gvrecords.DataBind();
}
Posted
Updated 16-Feb-12 23:45pm
v2
Comments
RDBurmon 17-Feb-12 5:43am    
Try IP instead of JDPANDEY-PC
Janardan Pandey 18-Feb-12 2:03am    
this is my personal laptop.How can i give IP.
Om Prakash Pant 17-Feb-12 5:46am    
can you paste the exact error that you are getting?
Janardan Pandey 18-Feb-12 2:04am    
Error also giving in da.Fill(ds);
Janardan Pandey 18-Feb-12 2:08am    
Error - Unrecognized escape sequence

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900