Refreshing SqlDataSource on page roundtrip?

G

Guest

Hi,

I have SqlDataSource control that makes a "select count" to show how many
rows there are in a Table and it is working fine on first page load.
The problem is that when I am inserting a new row to the database table at
the same ASPX page the rows count from the SqlDataSource remain the same.

To refresh the SqlDataSource I have used his
Select(DataSourceSelectArguments.Empty) but no luck.

How can I refresh the SqlDataSource after I am inserting a new row to the
database table using the TableAdapter?

Thanks in advanced for any help,
Asaf
 
S

Steven Cheng[MSFT]

Hello Asaf,

Are you use a SqlDatasource or ObjectDataSource control to retrieve the
Count of records in a table? Based on my understanding, only
ObjectDataSource can be configured to use TableAdapter component and
SqlDataSource will hide the code logic of underlying data accessing.

Also, after you have get the count data from
DataSourceControl(sqlDatasrouce or objectdatasource), how do you display
the value on control, use databinding (through DataSourceId) or manually
call DataSource.Select method and assign the return value to the target
control?

If you are using databinding approach, you just need to recall the
"DataBind" method of the target control(such as GridView ) after you've
peformed inserting or updating in the backend database. e.g.

suppose I use another DetailsView to insert data into backend data, I can
call the "GridView.DataBind" method in the DetailsView's "ItemInserted"
event to refresh the GridView (connected to a SqlDataSource):

============================
protected void DetailsView1_ItemInserted(object sender,
DetailsViewInsertedEventArgs e)
{
GridView1.DataBind();

}
==================

If you are programmatically get data through DataSource control, you can
also programmatically call DataSource.Select method to get the new value
(as long as you haven't enable cache on the datasource control) and assign
it to the target display control. e.g

==================
protected void DetailsView1_ItemInserted(object sender,
DetailsViewInsertedEventArgs e)
{
DataView dv =
SqlDataSource1.Select(DataSourceSelectArguments.Empty) as DataView;
lblCount.Text = dv[0][0].ToString();
}
================

Hope this helps. Please feel free to let me know if there is anything I
missed or if you have any other questions.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hello Steven,

Thanks for your help :)

Regards,
Asaf

Steven Cheng said:
Hello Asaf,

Are you use a SqlDatasource or ObjectDataSource control to retrieve the
Count of records in a table? Based on my understanding, only
ObjectDataSource can be configured to use TableAdapter component and
SqlDataSource will hide the code logic of underlying data accessing.

Also, after you have get the count data from
DataSourceControl(sqlDatasrouce or objectdatasource), how do you display
the value on control, use databinding (through DataSourceId) or manually
call DataSource.Select method and assign the return value to the target
control?

If you are using databinding approach, you just need to recall the
"DataBind" method of the target control(such as GridView ) after you've
peformed inserting or updating in the backend database. e.g.

suppose I use another DetailsView to insert data into backend data, I can
call the "GridView.DataBind" method in the DetailsView's "ItemInserted"
event to refresh the GridView (connected to a SqlDataSource):

============================
protected void DetailsView1_ItemInserted(object sender,
DetailsViewInsertedEventArgs e)
{
GridView1.DataBind();

}
==================

If you are programmatically get data through DataSource control, you can
also programmatically call DataSource.Select method to get the new value
(as long as you haven't enable cache on the datasource control) and assign
it to the target display control. e.g

==================
protected void DetailsView1_ItemInserted(object sender,
DetailsViewInsertedEventArgs e)
{
DataView dv =
SqlDataSource1.Select(DataSourceSelectArguments.Empty) as DataView;
lblCount.Text = dv[0][0].ToString();
}
================

Hope this helps. Please feel free to let me know if there is anything I
missed or if you have any other questions.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top