DataSourceSelectArguments error

A

ashkaan57

Hi all,
I am new to ASP.NET and VS 2005 Express.

I am having problems with an error message and can't figure out why.
I am trying to run a "SELECT" query triggered by a change in dropdown .
When I hit the line:

DataView dv =
(DataView)(SiteInfoDS.Select(DataSourceSelectArguments.Empty));
in the code below, I get:
"Format of initializaion string does not conform to specification
starting at index 0".

I changed it so DataSourceSelectArguments args = new
DataSourceSelectArguments();
and used args as the parameter, but I got the same error message. her
is the code:

("SiteName" is the name of the dropdown in the form, "SiteID" is a
field in table "Sites", also used as the value in the dropdown.)

protected void SiteName_SelectedIndexChanged(object sender,
EventArgs e)
{
SqlDataSource SiteInfoDS = new SqlDataSource();
DataSourceSelectArguments args = new
DataSourceSelectArguments();
String SelQuery = "SELECT * FROM Sites WHERE (SiteID
=@SiteID)";
SiteInfoDS.ConnectionString = "siteConnectionString";
SiteInfoDS.SelectCommandType = SqlDataSourceCommandType.Text;
SiteInfoDS.SelectCommand = SelQuery;
SiteInfoDS.SelectParameters.Add("siteID",
SiteName.SelectedValue);

DataView dv =
(DataView)(SiteInfoDS.Select(DataSourceSelectArguments.Empty));

foreach (DataRow dr in dv.Table.Rows)
{
AreaName.Text = dr["AreaName"].ToString();
SiteType.Text = dr["SiteTypeName"].ToString();
SiteFinance.Text = dr["FinanceNo"].ToString();
}
}

Thanks for your assistance.
 
G

Guest

Is there a reason you are using SqlDataSource & DataView? Both of these have
a lot of unneeded overhead in your case.

Maybe this will work (I have changed vb to c# in notepad so it may not be
correct):

String SelQuery = "SELECT * FROM Sites WHERE (SiteID=" &
SiteName.SelectedValue & ")";

SqlCommand oCMD = New SqlCommand(SelQuery, New
SqlConnection("siteconnectionstring"));
oCMD.Connection.Open();
SqlDataReader dr oCMD.ExecuteReader(CommandBehavior.CloseConnection);
While dr.Read {
AreaName.Text = dr["AreaName"].ToString();
SiteType.Text = dr["SiteTypeName"].ToString();
SiteFinance.Text = dr["FinanceNo"].ToString();
}
rdr.Close();

Far less overhead and by far a lot faster.
 
A

ashkaan57

Harolds said:
Is there a reason you are using SqlDataSource & DataView? Both of these have
a lot of unneeded overhead in your case.

Maybe this will work (I have changed vb to c# in notepad so it may not be
correct):

String SelQuery = "SELECT * FROM Sites WHERE (SiteID=" &
SiteName.SelectedValue & ")";

SqlCommand oCMD = New SqlCommand(SelQuery, New
SqlConnection("siteconnectionstring"));
oCMD.Connection.Open();
SqlDataReader dr oCMD.ExecuteReader(CommandBehavior.CloseConnection);
While dr.Read {
AreaName.Text = dr["AreaName"].ToString();
SiteType.Text = dr["SiteTypeName"].ToString();
SiteFinance.Text = dr["FinanceNo"].ToString();
}
rdr.Close();

Far less overhead and by far a lot faster.
--
Harolds


Hi all,
I am new to ASP.NET and VS 2005 Express.

I am having problems with an error message and can't figure out why.
I am trying to run a "SELECT" query triggered by a change in dropdown .
When I hit the line:

DataView dv =
(DataView)(SiteInfoDS.Select(DataSourceSelectArguments.Empty));
in the code below, I get:
"Format of initializaion string does not conform to specification
starting at index 0".

I changed it so DataSourceSelectArguments args = new
DataSourceSelectArguments();
and used args as the parameter, but I got the same error message. her
is the code:

("SiteName" is the name of the dropdown in the form, "SiteID" is a
field in table "Sites", also used as the value in the dropdown.)

protected void SiteName_SelectedIndexChanged(object sender,
EventArgs e)
{
SqlDataSource SiteInfoDS = new SqlDataSource();
DataSourceSelectArguments args = new
DataSourceSelectArguments();
String SelQuery = "SELECT * FROM Sites WHERE (SiteID
=@SiteID)";
SiteInfoDS.ConnectionString = "siteConnectionString";
SiteInfoDS.SelectCommandType = SqlDataSourceCommandType.Text;
SiteInfoDS.SelectCommand = SelQuery;
SiteInfoDS.SelectParameters.Add("siteID",
SiteName.SelectedValue);

DataView dv =
(DataView)(SiteInfoDS.Select(DataSourceSelectArguments.Empty));

foreach (DataRow dr in dv.Table.Rows)
{
AreaName.Text = dr["AreaName"].ToString();
SiteType.Text = dr["SiteTypeName"].ToString();
SiteFinance.Text = dr["FinanceNo"].ToString();
}
}

Thanks for your assistance.
Thanks for the reply Harold.
I am very ew to ASP.NET. I am from a C++ and PHP background and not
familiar with VB. The source you supplied generates a lot of erros in
C# and things like sqlCommand don't exist in C#.
Also, I had googled for this issues before posting to the group and all
the xamples used sqlDatSource. Same thing in tutorials I checked out.
What I don't understand is that the argument to SiteInfoDS.Select is
exactly what every example has used but mine generates an error.

Thanks.
 
G

Guest

Here is the debugged version of my code, which you could have easily had
done. Keep in mind that some lines of code get wrapped here and you will need
to unwrap them.

String SelQuery = string.Concat("SELECT * FROM Sites WHERE
(SiteID=",SiteName.SelectedValue.ToString(),")");

System.Data.SqlClient.SqlCommand oCMD = new
System.Data.SqlClient.SqlCommand(SelQuery, new
System.Data.SqlClient.SqlConnection("siteconnectionstring"));
oCMD.Connection.Open();
System.Data.SqlClient.SqlDataReader dr =
oCMD.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read() ){
AreaName.Text = dr["AreaName"].ToString();
SiteType.Text = dr["SiteTypeName"].ToString();
SiteFinance.Text = dr["FinanceNo"].ToString();
}
dr.Close();

And the problem with your code is your "siteconnectionstring" has to
actually be a connection string to your datasource, not just the word
siteconnectionstring. Which I discovered by debugging your code.
--
Harolds


Is there a reason you are using SqlDataSource & DataView? Both of these have
a lot of unneeded overhead in your case.

Maybe this will work (I have changed vb to c# in notepad so it may not be
correct):

String SelQuery = "SELECT * FROM Sites WHERE (SiteID=" &
SiteName.SelectedValue & ")";

SqlCommand oCMD = New SqlCommand(SelQuery, New
SqlConnection("siteconnectionstring"));
oCMD.Connection.Open();
SqlDataReader dr oCMD.ExecuteReader(CommandBehavior.CloseConnection);
While dr.Read {
AreaName.Text = dr["AreaName"].ToString();
SiteType.Text = dr["SiteTypeName"].ToString();
SiteFinance.Text = dr["FinanceNo"].ToString();
}
rdr.Close();

Far less overhead and by far a lot faster.
--
Harolds


Hi all,
I am new to ASP.NET and VS 2005 Express.

I am having problems with an error message and can't figure out why.
I am trying to run a "SELECT" query triggered by a change in dropdown .
When I hit the line:

DataView dv =
(DataView)(SiteInfoDS.Select(DataSourceSelectArguments.Empty));
in the code below, I get:
"Format of initializaion string does not conform to specification
starting at index 0".

I changed it so DataSourceSelectArguments args = new
DataSourceSelectArguments();
and used args as the parameter, but I got the same error message. her
is the code:

("SiteName" is the name of the dropdown in the form, "SiteID" is a
field in table "Sites", also used as the value in the dropdown.)

protected void SiteName_SelectedIndexChanged(object sender,
EventArgs e)
{
SqlDataSource SiteInfoDS = new SqlDataSource();
DataSourceSelectArguments args = new
DataSourceSelectArguments();
String SelQuery = "SELECT * FROM Sites WHERE (SiteID
=@SiteID)";
SiteInfoDS.ConnectionString = "siteConnectionString";
SiteInfoDS.SelectCommandType = SqlDataSourceCommandType.Text;
SiteInfoDS.SelectCommand = SelQuery;
SiteInfoDS.SelectParameters.Add("siteID",
SiteName.SelectedValue);

DataView dv =
(DataView)(SiteInfoDS.Select(DataSourceSelectArguments.Empty));

foreach (DataRow dr in dv.Table.Rows)
{
AreaName.Text = dr["AreaName"].ToString();
SiteType.Text = dr["SiteTypeName"].ToString();
SiteFinance.Text = dr["FinanceNo"].ToString();
}
}

Thanks for your assistance.
Thanks for the reply Harold.
I am very ew to ASP.NET. I am from a C++ and PHP background and not
familiar with VB. The source you supplied generates a lot of erros in
C# and things like sqlCommand don't exist in C#.
Also, I had googled for this issues before posting to the group and all
the xamples used sqlDatSource. Same thing in tutorials I checked out.
What I don't understand is that the argument to SiteInfoDS.Select is
exactly what every example has used but mine generates an error.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top