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

  • Thread starter Thread starter Martin Arvidsson
  • Start date Start date
M

Martin Arvidsson

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
 
Hi Martin,

Yeah, that sucks. Remove the expression before doing update and reapply it
after.
Perhaps there is a better solution out there..
 
Sorry for a perhaps stupid follow up question.

What expression should i remove before update :)

Regards
Martin

Miha Markic said:
Hi Martin,

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

--
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 said:
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
 
Martin Arvidsson said:
Sorry for a perhaps stupid follow up question.

What expression should i remove before update :)

DataColumn.Expression = null;

Or even better, remove entire column :-)
 
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
 
What code snipp do you want me to send to you?

There is a lot of code ;)

Regards
Martin


Miha Markic said:
Hi Martin,

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

--
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 said:
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
 
What code snipp do you want me to send to you?

There is a lot of code ;)

Regards
Martin


Miha Markic said:
Hi Martin,

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

--
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 said:
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
 
Just the adapter's insert and update commands..

--
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 said:
What code snipp do you want me to send to you?

There is a lot of code ;)

Regards
Martin


Miha Markic said:
Hi Martin,

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

--
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 said:
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


"Miha Markic [MVP C#]" <miha at rthand com> skrev i meddelandet

Sorry for a perhaps stupid follow up question.

What expression should i remove before update :)

DataColumn.Expression = null;

Or even better, remove entire column :-)
 
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();
}
}
}




Miha Markic said:
Just the adapter's insert and update commands..

--
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 said:
What code snipp do you want me to send to you?

There is a lot of code ;)

Regards
Martin


Miha Markic said:
Hi Martin,

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

--
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.

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


"Miha Markic [MVP C#]" <miha at rthand com> skrev i meddelandet

Sorry for a perhaps stupid follow up question.

What expression should i remove before update :)

DataColumn.Expression = null;

Or even better, remove entire column :-)
 

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

Back
Top