foreach
(DataRowView
drv in
SqlDataSourcePin.Select(DataSourceSelectArguments.Empty))
{
if
(drv["PERSONNEL_PIN"].ToString()
== args.Value)
{ args.IsValid =false;
break;
}
}
if
(args.IsValid)
lblResult.Text ="Congratulations!
That name is not taken.";
}
This works fine, I now want to use an ObjectDataSource called ODSStaffPin and get rid of the SQLDatasource so it is consistent with the rest of my site. How would I convert the code above to use an ODS as the methods are not the same.? My ODS returns a datatable.
args.IsValid =true; ObjectDataSourcePin.SelectParameters["Company_id"].DefaultValue
= your value 1; ObjectDataSourcePin.SelectParameters["Site_id"].DefaultValue
= your value 2;
foreach (DataRowView drv in
ObjectDataSourcePin.Select())
{
if (drv["PERSONNEL_PIN"].ToString()
== args.Value)
{ args.IsValid =false;
break;
}
}
if (args.IsValid)
lblResult.Text ="Congratulations! That name is not taken.";
AndyMayo
0 Points
2 Posts
SqlDataSource to ObjectDataSource
Apr 26, 2012 10:25 AM|LINK
Hello
I have this code in my code behind file on a testpage
protected void custval_txtPin_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid =true;
foreach (DataRowView drv in SqlDataSourcePin.Select(DataSourceSelectArguments.Empty))
{
if (drv["PERSONNEL_PIN"].ToString() == args.Value)
{ args.IsValid =false;
break;
}
}
if (args.IsValid)
lblResult.Text ="Congratulations! That name is not taken.";
}
This works fine, I now want to use an ObjectDataSource called ODSStaffPin and get rid of the SQLDatasource so it is consistent with the rest of my site. How would I convert the code above to use an ODS as the methods are not the same.? My ODS returns a datatable.
This is my Business Layer
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select,true)]
public SiteManager.App_Code.DAL.sitemanager2.PERSONNELDataTable GetStaffPin(int Company_id, int Site_id)
{
return Adapter.GetStaffPin(Company_id, Site_id);
}
It returns a single column PERSONNEL_ID.
Thanks
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: SqlDataSource to ObjectDataSource
Apr 28, 2012 01:01 AM|LINK
Hello:)
Since your ObjectDataSource needs some parameters……So you'd assign these parameters with proper values and then do to call Select method:
protected void custval_txtPin_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid =true;
ObjectDataSourcePin.SelectParameters["Company_id"].DefaultValue = your value 1;
ObjectDataSourcePin.SelectParameters["Site_id"].DefaultValue = your value 2;
foreach (DataRowView drv in ObjectDataSourcePin.Select())
{
if (drv["PERSONNEL_PIN"].ToString() == args.Value)
{ args.IsValid =false;
break;
}
}
if (args.IsValid)
lblResult.Text ="Congratulations! That name is not taken.";
}