Showing posts with label experiencing. Show all posts
Showing posts with label experiencing. Show all posts

Tuesday, March 27, 2012

Binding a SqlDataSource, to a GridView at Runtime

Hello

I'm experiencing some problems, binding a SqlDataSource to a GridView.

The following code creates the SqlDataSource:
string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string strProvider = ConfigurationManager.ConnectionStrings["ConnectionString"].ProviderName;

SqlDataSource ds = new SqlDataSource(strProvider, strConn);
ds.SelectCommand = "SELECT * FROM rammekategori";

Then i bind the SqlDataSource to a GridView:

GridView1.DataSource = ds;
GridView1.DataBind();

ErrorMessage:

Format of the initialization string does not conform to specification starting at index 0.

Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

Line 24: GridView1.DataBind();

Am i totally off target here? Can it be something about, that you have to set the datasource of the gridview, before the Page_Load event?

Thanks - MartinHN

You are probably not going to be happy with the results if you do manage to fix your immediate error. May I suggest you actually put the SqlDataSource in the .aspx page? You can then bind it in code, but don't change the select statement in code, as that too will cause some issues.|||

oh. The code was copied from VS2005, i forgot one important detail.

I add the SqlDataSource to the page, by using Page.Controls.Add(ds);

Still, i get the error, even if i set the DataSource property of the gridview like this:

GridView1.DataSource = (SqlDataSource)Page.FindControl("ds");

--

MartinHN

|||

What if you try this:

SqlDataSource m_SqlDataSource = Page.FindControl("ds") as SqlDataSource;

if (m_SqlDataSource != null)
{
GridView1.DataSourceID = m_SqlDataSource.ID;
GridView1.DataBind();
}

HTH,
Ryan

|||

>>>>What if you try this:

SqlDataSource m_SqlDataSource = Page.FindControl("ds") as SqlDataSource;

if (m_SqlDataSource != null)
{
GridView1.DataSourceID = m_SqlDataSource.ID;
GridView1.DataBind();
}

Still no success... It is still the samme error message:Format of the initialization string does not conform to specification starting at index 0.

I was wondering, if i need to set a couple of more properties on my SqlDataSource.

One thing i just tried, was createing a new SqlDataSource directly on the aspx page, from the Designer in VS2005. The i set the datasource, to the FindControl method, with the name as the parameter. That worked. But i'm interessted in getting a SqlDataSource object, from lower tier, than the page it self. So that i have a complete SqlDataSource with select, update, delete and insert commands, to use along with the gridview...


|||

Ah. I totally missed the actual error. Please post your connection string, leaving out any login information, but keep the formatting as-is.

|||

ok...

The connectionstring i am using are as follows:

<connectionStrings>
<add name="ConnectionString" connectionString="DRIVER={MySQL ODBC 3.51 Driver};SERVER=myserverip;DATABASE=mydb;UID=myuid;PASSWORD=mypwd;" providerName="System.Data.Odbc" />
</connectionStrings>

Should there be any troubles using a mySQL DB?

|||

I think I see your problem. The overloads for the SqlDataSource on MSDN are as follows:

SqlDataSource()
SqlDataSource(string connectionString, string selectCommand)
SqlDataSource(string providerName, string connectionString, string selectCommand)

So, you should be doing something like this:

string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string strProvider = ConfigurationManager.ConnectionStrings["ConnectionString"].ProviderName;
string selectCommand = "SELECT * FROM rammekategori";

SqlDataSource ds = new SqlDataSource(strProvider, strConn, selectCommand);

HTH,
Ryan

|||

Ryan - I really cannot find a way to show my appreciation... That was very nice to have sorted out, thanks for your help.

What about insert, delete and update commands, can i set them after I've instantiated the SqlDataSource object?

|||

martinhn wrote:

What about insert, delete and update commands, can i set them after I've instantiated the SqlDataSource object?

Yes.

SqlDataSource.DeleteCommand
SqlDataSource.InsertCommand
SqlDataSource.UpdateCommand

HTH,
Ryan

sql

Monday, March 19, 2012

BIDS Variable Window Disappeared

I am experiencing a weird problem with SSIS development in BIDS...
When I click "View --> Other Windows --> Variables", the window doesn't show
up.
Has anyone else had this issue? If so did you solve it, and how?
Thanks!Hello Dan,
The actual window itself or the ability to edit variables?
Are you sure the window isn't already open just tabbed with the toolbox or
something like that?
What build are you running?
Allan Mitchell
http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
http://www.konesans.com

> I am experiencing a weird problem with SSIS development in BIDS...
> When I click "View --> Other Windows --> Variables", the window
> doesn't show up.
> Has anyone else had this issue? If so did you solve it, and how?
> Thanks!
>|||Allan,
Thanks for the reply.
The window itself doesn't show up. I have the window in auto-hide on the
left (with the toolbox on the left). When I traverse the menu (as stated) a
blank box appears as if it is trying to show me what I've asked.
I can get to (and edit) the variables by using the package explorer tab -
just not from the variables window.
Here are the builds of the different products I'm using:
-Microsoft Visual Studio Team Edition for Database Professionals Version
2.0.50727.251
-Microsoft Visual Studio 2005 Team Explorer
Version 8.0.50727.762
-Microsoft SQL Server Integration Services Designer
Version 9.00.3042.00
Thanks again for the help...
"Allan Mitchell" wrote:

> Hello Dan,
> The actual window itself or the ability to edit variables?
> Are you sure the window isn't already open just tabbed with the toolbox or
> something like that?
> What build are you running?
>
> --
> Allan Mitchell
> http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
> http://www.konesans.com
>
>
>

BIDS Variable Window Disappeared

I am experiencing a weird problem with SSIS development in BIDS...
When I click "View --> Other Windows --> Variables", the window doesn't show
up.
Has anyone else had this issue? If so did you solve it, and how?
Thanks!
Hello Dan,
The actual window itself or the ability to edit variables?
Are you sure the window isn't already open just tabbed with the toolbox or
something like that?
What build are you running?

Allan Mitchell
http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
http://www.konesans.com

> I am experiencing a weird problem with SSIS development in BIDS...
> When I click "View --> Other Windows --> Variables", the window
> doesn't show up.
> Has anyone else had this issue? If so did you solve it, and how?
> Thanks!
>
|||Allan,
Thanks for the reply.
The window itself doesn't show up. I have the window in auto-hide on the
left (with the toolbox on the left). When I traverse the menu (as stated) a
blank box appears as if it is trying to show me what I've asked.
I can get to (and edit) the variables by using the package explorer tab -
just not from the variables window.
Here are the builds of the different products I'm using:
-Microsoft Visual Studio Team Edition for Database Professionals Version
2.0.50727.251
-Microsoft Visual Studio 2005 Team Explorer
Version 8.0.50727.762
-Microsoft SQL Server Integration Services Designer
Version 9.00.3042.00
Thanks again for the help...
"Allan Mitchell" wrote:

> Hello Dan,
> The actual window itself or the ability to edit variables?
> Are you sure the window isn't already open just tabbed with the toolbox or
> something like that?
> What build are you running?
>
> --
> Allan Mitchell
> http://wiki.sqlis.com | http://www.sqlis.com | http://www.sqldts.com |
> http://www.konesans.com
>
>