Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 Dynamic Paging For DataList Control with PagedDataSource
Posted by Charlie Childs on  4/7/2010 11:41:57 AM Category: ADO.NET
Add to my favorites
Email to friend
I have been looking for a solution to page a datalist and was very pleased to find because the results demonstrated look brilliant.

I got an exception at quite an early stage in the tutorial but persevered to the end of the lesson in the hope that I would find a solution to the exception. Unfortunately I cannot so i would be very grateful if anyone can help.

The tutorial uses a Country database but I use my own training database. Aside from that I have all the code from the tutorial placed in my pages and there are no squiggly lines.

My error comes from line 4 of the below extract from the code behind in default.aspx.cs.

1 private void BindGrid()
2 {
3 string sql = "SELECT [Title] FROM [TableSG1] ORDER BY [Title] DESC";
4 SqlDataAdapter da = new SqlDataAdapter(sql,"ConnectionStrings:ConnectionString");
5 DataTable dt = new DataTable();
6 da.Fill(dt);

The exception is "Format of the initialization string does not conform to specification starting at index 0"

I copied my connection string from the default.aspx page after adding the datasource.
(In the tutorial there was nothing said about adding the datasource but I decided that having the datasource was probable one of those things that goes without saying because it produced a connection string).
I have tried using the connection string from the webconfig file but squiggly lines told me to forget that idea.

I have searched online and have tried various possible remedies used for other similar problems but I do not have the experience to truly understand how to proceed.

I have the pager stting on my disign page as it should be and think it is ready to use apart from this line of code not working and preventing debug.

Please help

Post Your Reply Post New Question

 Viewer's Reply
Problem in Connection String
Answered By Moderator1 on 4/8/2010 8:27:08 AM

As per the exception you got, I suggest you to change the value you set for connection string. In the article, "YourConnectionString" means you need to replace this word with your connection string. So please check have you set the connection string in your web.config file. if so, you can access the connectionstring with below syntax.


So the Line 4 will look like

SqlDataAdapter da = new SqlDataAdapter(sql,ConfigurationManager.ConnectionStrings["TestCnStr"].ConnectionString);

Try like. It will solve your problem. Good luck.
Post Your Reply If you still have problem, post it again under this reply for better response.

Sponsored by
Programmers Heaven C# School Book - Free 338 Page eBook
Oracle Magazine
Backup and Recovery Best Practices for Microsoft SQL Server 2005