I have the below code writted on the Button click event.
SqlDataSource3.SelectCommand = "SELECT * FROM [IDMServices] WHERE Region='" + DropDownList1.SelectedValue + "' and Country ='" + DropDownList2.SelectedValue + "'";
SqlDataSource3.DataBind();
I need to check if the above query returns any value or returns null? For this the Selected event does'nt get fired, which gives the affeted rows.
protected void SqlDataSource3_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
int ef = e.AffectedRows;
}
If you are not using GridView or something like this,I think you can just use a common SqlCommand to check whether rows are effected or not by checking its count:
using (SqlCommand cmd = new SqlCommand("SELECT count(Your Primary Key Name) FROM [IDMServices] WHERE Region='" + DropDownList1.SelectedValue + "' and Country ='" + DropDownList2.SelectedValue + "'",new SqlConnection(“…………”)))
{
cmd.Connection.Open();
int count = (int)cmd.ExecuteScalar();
if(count>0)
{
//Do what you want here…………
}
ashiqf
Participant
868 Points
397 Posts
SQLDatasource Select Method
Apr 26, 2012 08:23 AM|LINK
Hi All,
I have the below code writted on the Button click event.
SqlDataSource3.SelectCommand = "SELECT * FROM [IDMServices] WHERE Region='" + DropDownList1.SelectedValue + "' and Country ='" + DropDownList2.SelectedValue + "'"; SqlDataSource3.DataBind();I need to check if the above query returns any value or returns null? For this the Selected event does'nt get fired, which gives the affeted rows.
protected void SqlDataSource3_Selected(object sender, SqlDataSourceStatusEventArgs e) { int ef = e.AffectedRows; }Ashiq
nijhawan.sau...
All-Star
16432 Points
3174 Posts
Re: SQLDatasource Select Method
Apr 26, 2012 09:18 AM|LINK
I guess it'd be called when you bind the data to a control like:
ashiqf
Participant
868 Points
397 Posts
Re: SQLDatasource Select Method
Apr 26, 2012 09:58 AM|LINK
I am not using a Gridview.
Ashiq
nijhawan.sau...
All-Star
16432 Points
3174 Posts
Re: SQLDatasource Select Method
Apr 26, 2012 10:10 AM|LINK
Well then you must be using some UI control to display the data correct?
Use its DataBind method.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: SQLDatasource Select Method
Apr 28, 2012 12:33 AM|LINK
Hello ashiqf:)
If you are not using GridView or something like this,I think you can just use a common SqlCommand to check whether rows are effected or not by checking its count:
using (SqlCommand cmd = new SqlCommand("SELECT count(Your Primary Key Name) FROM [IDMServices] WHERE Region='" + DropDownList1.SelectedValue + "' and Country ='" + DropDownList2.SelectedValue + "'",new SqlConnection(“…………”)))
{
cmd.Connection.Open();
int count = (int)cmd.ExecuteScalar();
if(count>0)
{
//Do what you want here…………
}
}