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 / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Q: Displaying computed database fields, gives error on saving...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martin Arvidsson - 27 Oct 2006 21:45 GMT
Hi!

I have two computed datafields that i am displaying in my windowsform.

When i try to update the dataset and commit the transaction.

I get an error message telling me that i cant update calculated fields. That
i can understand
but how to tell the dataset or what ever to NOT do this update to the
server?

Regards
Martin
Miha Markic [MVP C#] - 29 Oct 2006 23:09 GMT
Hi Martin,

Yeah, that sucks. Remove the expression before doing update and reapply it
after.
Perhaps there is a better solution out there..

Signature

Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

> Hi!
>
[quoted text clipped - 9 lines]
> Regards
> Martin
Martin Arvidsson - 30 Oct 2006 20:59 GMT
Sorry for a perhaps stupid follow up question.

What expression should i remove before update :)

Regards
Martin

> Hi Martin,
>
[quoted text clipped - 15 lines]
>> Regards
>> Martin
Miha Markic [MVP C#] - 31 Oct 2006 14:49 GMT
> Sorry for a perhaps stupid follow up question.
>
> What expression should i remove before update :)

DataColumn.Expression = null;

Or even better, remove entire column :-)

Signature

Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Martin Arvidsson - 31 Oct 2006 20:08 GMT
Ok, but here is the tricky part.

The column is computed in the table level at the sql server.

So i guess i have to exclude the fields and build a view that shows the
fields where thay can't be modifyed.

I was so stupid to believe that C# could be integrated smoothly with fields
like this ;)

Regards
Martin

>> Sorry for a perhaps stupid follow up question.
>>
[quoted text clipped - 3 lines]
>
> Or even better, remove entire column :-)
Miha Markic [MVP C#] - 01 Nov 2006 09:04 GMT
Hi Martin,

Aha, I was under impression that you use DataColumn.Expression.
Now, what does your adapter's code look like?

Signature

Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

> Ok, but here is the tricky part.
>
[quoted text clipped - 16 lines]
>>
>> Or even better, remove entire column :-)
Martin Arvidsson - 02 Nov 2006 23:18 GMT
What code snipp do you want me to send to you?

There is a lot of code ;)

Regards
Martin

> Hi Martin,
>
[quoted text clipped - 21 lines]
>>>
>>> Or even better, remove entire column :-)
Martin Arvidsson - 02 Nov 2006 23:18 GMT
What code snipp do you want me to send to you?

There is a lot of code ;)

Regards
Martin

> Hi Martin,
>
[quoted text clipped - 21 lines]
>>>
>>> Or even better, remove entire column :-)
Miha Markic [MVP C#] - 02 Nov 2006 23:26 GMT
Just the adapter's insert and update commands..

Signature

Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

> What code snipp do you want me to send to you?
>
[quoted text clipped - 28 lines]
>>>>
>>>> Or even better, remove entire column :-)
Martin Arvidsson - 13 Nov 2006 19:20 GMT
Hi Miha!

Here comes the code finaly...

The fieldname is TotalWorkHour

/Regards
Martin

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert,
true)]
public virtual int Insert(int ProjectSub, int ProjectMain, string
Description, System.Nullable<bool> ProjectLocked, System.Nullable<int>
TotalWorkTime, int CustomerNo, int ContactID, string DescriptionOfProject,
System.Nullable<int> TotalWorkHour) {
this.Adapter.InsertCommand.Parameters[0].Value = ((int)(ProjectSub));
this.Adapter.InsertCommand.Parameters[1].Value = ((int)(ProjectMain));
if ((Description == null)) {
throw new System.ArgumentNullException("Description");
}
else {
this.Adapter.InsertCommand.Parameters[2].Value = ((string)(Description));
}
if ((ProjectLocked.HasValue == true)) {
this.Adapter.InsertCommand.Parameters[3].Value =
((bool)(ProjectLocked.Value));
}
else {
this.Adapter.InsertCommand.Parameters[3].Value = System.DBNull.Value;
}
if ((TotalWorkTime.HasValue == true)) {
this.Adapter.InsertCommand.Parameters[4].Value =
((int)(TotalWorkTime.Value));
}
else {
this.Adapter.InsertCommand.Parameters[4].Value = System.DBNull.Value;
}
this.Adapter.InsertCommand.Parameters[5].Value = ((int)(CustomerNo));
this.Adapter.InsertCommand.Parameters[6].Value = ((int)(ContactID));
if ((DescriptionOfProject == null)) {
this.Adapter.InsertCommand.Parameters[7].Value = System.DBNull.Value;
}
else {
this.Adapter.InsertCommand.Parameters[7].Value =
((string)(DescriptionOfProject));
}
if ((TotalWorkHour.HasValue == true)) {
this.Adapter.InsertCommand.Parameters[8].Value =
((int)(TotalWorkHour.Value));
}
else {
this.Adapter.InsertCommand.Parameters[8].Value = System.DBNull.Value;
}
System.Data.ConnectionState previousConnectionState =
this.Adapter.InsertCommand.Connection.State;
if (((this.Adapter.InsertCommand.Connection.State &
System.Data.ConnectionState.Open)
!= System.Data.ConnectionState.Open)) {
this.Adapter.InsertCommand.Connection.Open();
}
try {
int returnValue = this.Adapter.InsertCommand.ExecuteNonQuery();
return returnValue;
}
finally {
if ((previousConnectionState == System.Data.ConnectionState.Closed)) {
this.Adapter.InsertCommand.Connection.Close();
}
}
}
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update,
true)]
public virtual int Update(
int ProjectSub,
int ProjectMain,
string Description,
System.Nullable<bool> ProjectLocked,
System.Nullable<int> TotalWorkTime,
int CustomerNo,
int ContactID,
string DescriptionOfProject,
System.Nullable<int> TotalWorkHour,
int Original_ProjectID,
int Original_ProjectSub,
int Original_ProjectMain,
string Original_Description,
System.Nullable<bool> Original_ProjectLocked,
System.Nullable<int> Original_TotalWorkTime,
int Original_CustomerNo,
int Original_ContactID,
System.Nullable<int> Original_TotalWorkHour,
int ProjectID) {
this.Adapter.UpdateCommand.Parameters[0].Value = ((int)(ProjectSub));
this.Adapter.UpdateCommand.Parameters[1].Value = ((int)(ProjectMain));
if ((Description == null)) {
throw new System.ArgumentNullException("Description");
}
else {
this.Adapter.UpdateCommand.Parameters[2].Value = ((string)(Description));
}
if ((ProjectLocked.HasValue == true)) {
this.Adapter.UpdateCommand.Parameters[3].Value =
((bool)(ProjectLocked.Value));
}
else {
this.Adapter.UpdateCommand.Parameters[3].Value = System.DBNull.Value;
}
if ((TotalWorkTime.HasValue == true)) {
this.Adapter.UpdateCommand.Parameters[4].Value =
((int)(TotalWorkTime.Value));
}
else {
this.Adapter.UpdateCommand.Parameters[4].Value = System.DBNull.Value;
}
this.Adapter.UpdateCommand.Parameters[5].Value = ((int)(CustomerNo));
this.Adapter.UpdateCommand.Parameters[6].Value = ((int)(ContactID));
if ((DescriptionOfProject == null)) {
this.Adapter.UpdateCommand.Parameters[7].Value = System.DBNull.Value;
}
else {
this.Adapter.UpdateCommand.Parameters[7].Value =
((string)(DescriptionOfProject));
}
if ((TotalWorkHour.HasValue == true)) {
this.Adapter.UpdateCommand.Parameters[8].Value =
((int)(TotalWorkHour.Value));
}
else {
this.Adapter.UpdateCommand.Parameters[8].Value = System.DBNull.Value;
}
this.Adapter.UpdateCommand.Parameters[9].Value =
((int)(Original_ProjectID));
this.Adapter.UpdateCommand.Parameters[10].Value =
((int)(Original_ProjectSub));
this.Adapter.UpdateCommand.Parameters[11].Value =
((int)(Original_ProjectMain));
if ((Original_Description == null)) {
throw new System.ArgumentNullException("Original_Description");
}
else {
this.Adapter.UpdateCommand.Parameters[12].Value =
((string)(Original_Description));
}
if ((Original_ProjectLocked.HasValue == true)) {
this.Adapter.UpdateCommand.Parameters[13].Value = ((object)(0));
this.Adapter.UpdateCommand.Parameters[14].Value =
((bool)(Original_ProjectLocked.Value));
}
else {
this.Adapter.UpdateCommand.Parameters[13].Value = ((object)(1));
this.Adapter.UpdateCommand.Parameters[14].Value = System.DBNull.Value;
}
if ((Original_TotalWorkTime.HasValue == true)) {
this.Adapter.UpdateCommand.Parameters[15].Value = ((object)(0));
this.Adapter.UpdateCommand.Parameters[16].Value =
((int)(Original_TotalWorkTime.Value));
}
else {
this.Adapter.UpdateCommand.Parameters[15].Value = ((object)(1));
this.Adapter.UpdateCommand.Parameters[16].Value = System.DBNull.Value;
}
this.Adapter.UpdateCommand.Parameters[17].Value =
((int)(Original_CustomerNo));
this.Adapter.UpdateCommand.Parameters[18].Value =
((int)(Original_ContactID));
if ((Original_TotalWorkHour.HasValue == true)) {
this.Adapter.UpdateCommand.Parameters[19].Value = ((object)(0));
this.Adapter.UpdateCommand.Parameters[20].Value =
((int)(Original_TotalWorkHour.Value));
}
else {
this.Adapter.UpdateCommand.Parameters[19].Value = ((object)(1));
this.Adapter.UpdateCommand.Parameters[20].Value = System.DBNull.Value;
}
this.Adapter.UpdateCommand.Parameters[21].Value = ((int)(ProjectID));
System.Data.ConnectionState previousConnectionState =
this.Adapter.UpdateCommand.Connection.State;
if (((this.Adapter.UpdateCommand.Connection.State &
System.Data.ConnectionState.Open)
!= System.Data.ConnectionState.Open)) {
this.Adapter.UpdateCommand.Connection.Open();
}
try {
int returnValue = this.Adapter.UpdateCommand.ExecuteNonQuery();
return returnValue;
}
finally {
if ((previousConnectionState == System.Data.ConnectionState.Closed)) {
this.Adapter.UpdateCommand.Connection.Close();
}
}
}

> Just the adapter's insert and update commands..
>
[quoted text clipped - 30 lines]
>>>>>
>>>>> Or even better, remove entire column :-)

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.