Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / April 2008

Tip: Looking for answers? Try searching our database.

DataSets and default columns

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Baldwin - 09 Apr 2008 14:56 GMT
We have a 3 tiered application. Table <tblx> resides in SQL2005, the DataSet
<dsx> is defined in the web service. The client creates instances of <dsx>
and passes them to the web service for storage/processing.

The table <tblx> has a column "EntryDate" with a default value of
"CURRENT_TIMESTAMP". When the DataSet <dsx> is generated from the table, the
EntryDate column is set to AllowNulls=false and the INSERT statement in the
TableAdapter includes the EntryDate column.

Before I can use this DataSet I have to change AllowNulls to true, otherwise
this column has to be filled in by the client before it can be sent the
DataSet to the WebService. I also have to change the TableAdapters INSERT
statement so as not to include the EntryDate column - since its
automatically populated by SQLServer.

This isn't too much of a problem, but everytime I modify the table structure
I have to remember to do these two things after refreshing the DataSet and
to be honest it's becoming a bit long in the tooth.

Is there a way around these problems? I know I can set the EntryDate column
in the table to AllowNulls but I don't want to do this, it's just not good
practise to allow UI problems to be solved in the data layer.

Signature

Best regards
Mark

Steven Cheng [MSFT] - 10 Apr 2008 04:13 GMT
Hi Mark,

Based on your description, I understand that you have some Typed
DataSet/DataTables generated from database and will be transferred between
client and server through webservice. However, one of the table column is
set to AllowNull= false while you will need it be set to "true" when using
it at client or server code, correct?

As for the auto-generated typed-dataset, when you reconfigure it from
database, it does overwrite the original one therefore, if we manually make
any changes on the dataset/table adapter, it will be changed after we
update it from database.  Also, I can understand your concern that it's
better to keep data access code away from UI layer.

Currently I think we still need to write some custom code to set the
"AllowNull" property. However, to prevent the code from being overwrite
when update dataset or not coupled with UI layer, you may consider the
following approach:

**In .NET 2.0, auto-generated typed dataset/datatables use parital classes.
Thus, you can also add another partial class file to extend the certain
typed DataSet or DataTable(and its TableAdapter).

#Extending Typed DataSets - Sorting Child Rows
http://www.madprops.org/cs/blogs/mabster/pages/extending-datasets-sorting-ch
ild-rows.aspx

You can add some custom method for the TableAdapter (which change the
AllowNull property of the certain DataTable  or use your own SqlCommand
object for updating, inserting). You encapsulate all these code logic in a
single custom method.

e.g.

===============
public partial class personsDataTable {
           
           private global::System.Data.DataColumn columnid;
           private global::System.Data.DataColumn columnname;
           ...

public MyInit()
{
this.columnname.AllowDBNull = true;
}
..
=============
           

** In your actual code(in client or server application) which use this
TypedDataSet, you can simply call the custom function you defined above(at
the begining when you create an instance of that datatable). Though it
still require you to manually call the method, it reduce much data access
specific code.

How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

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

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

--------------------
From: "Mark Baldwin" <sWozzi3@community.nospam>
Subject: DataSets and default columns
Date: Wed, 9 Apr 2008 14:56:59 +0100

We have a 3 tiered application. Table <tblx> resides in SQL2005, the
DataSet
<dsx> is defined in the web service. The client creates instances of <dsx>
and passes them to the web service for storage/processing.

The table <tblx> has a column "EntryDate" with a default value of
"CURRENT_TIMESTAMP". When the DataSet <dsx> is generated from the table,
the
EntryDate column is set to AllowNulls=false and the INSERT statement in the
TableAdapter includes the EntryDate column.

Before I can use this DataSet I have to change AllowNulls to true,
otherwise
this column has to be filled in by the client before it can be sent the
DataSet to the WebService. I also have to change the TableAdapters INSERT
statement so as not to include the EntryDate column - since its
automatically populated by SQLServer.

This isn't too much of a problem, but everytime I modify the table
structure
I have to remember to do these two things after refreshing the DataSet and
to be honest it's becoming a bit long in the tooth.

Is there a way around these problems? I know I can set the EntryDate column
in the table to AllowNulls but I don't want to do this, it's just not good
practise to allow UI problems to be solved in the data layer.

Signature

Best regards
Mark

Mark Baldwin - 14 Apr 2008 11:38 GMT
Steven

Thanks for your reply, however the typed datasets are defined in the web
service and there seems to way to open the partial class code window -
double clicking on the design surface does nothing. I can do this in the
client for a client specific dataset, but not in the web service.

Signature

Best regards
Mark Baldwin

> Hi Mark,
>
[quoted text clipped - 107 lines]
> in the table to AllowNulls but I don't want to do this, it's just not good
> practise to allow UI problems to be solved in the data layer.
Steven Cheng [MSFT] - 15 Apr 2008 03:38 GMT
Thanks for your reply Mark,

Yes, when you use the "WebSite" project model for ASP.NET 2.0+ Web
application/webservice, it use a dynamic compilation mode. Thus, some
components such as Typed Dataset, webservice proxy will not show the
auto-generated code file.  For such scenario, a common approach is move the
Typed Dataset into a class library project. Thus, you can add partial class
file for the typed dataset in the class library project. And in your
ASP.NET webservice project, you can reference the class library assembly to
use the typed Dataset. Do you think it workable for your scenario?

If there is any further questions, welcome to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

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

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

--------------------
From: "Mark Baldwin" <sWozzi3@community.nospam>
References: <O2dGOlkmIHA.3780@TK2MSFTNGP06.phx.gbl>
<qoj2djrmIHA.9932@TK2MSFTNGHUB02.phx.gbl>
Subject: Re: DataSets and default columns
Date: Mon, 14 Apr 2008 11:38:38 +0100

Steven

Thanks for your reply, however the typed datasets are defined in the web
service and there seems to way to open the partial class code window -
double clicking on the design surface does nothing. I can do this in the
client for a client specific dataset, but not in the web service.

Signature

Best regards
Mark Baldwin

> Hi Mark,
>
[quoted text clipped - 22 lines]
>
> #Extending Typed DataSets - Sorting Child Rows

http://www.madprops.org/cs/blogs/mabster/pages/extending-datasets-sorting-ch
> ild-rows.aspx
>
[quoted text clipped - 41 lines]
> ==================================================
> Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
>
[quoted text clipped - 34 lines]
> in the table to AllowNulls but I don't want to do this, it's just not good
> practise to allow UI problems to be solved in the data layer.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.