2

I am trying to update some field in my data table. While using the given below code shows one error. Help me to find a proper solution. Thank you.

Code:

ShadingAnalysisDataSetTableAdapters.tbl_AutoAssignJrEngineersTeamTableAdapter tm;
tm = new ShadingAnalysisDataSetTableAdapters.tbl_AutoAssignJrEngineersTeamTableAdapter();
DataTable dt = new DataTable();
dt = tm.UpdateTeam(AssignedTeam,userName,DateTime.Now,ID); // error popup here

SQL:

UPDATE tbl_AutoAssignJrEngineersTeam 
SET Assigned_Team = @Assigned_Team, 
    Updated_By = @Updated_By, 
    Updated_Date = @Updated_Date 
WHERE (Id = @Id)

DataBase:

enter image description here

2
  • 2
    Somewhere you have an int and try to cast it explicitly or implicitly to a DataTable. My guess would be the tm.UpdateTeam method returns an int. Commented Nov 7, 2014 at 10:59
  • possible duplicate of Cannot implicitly convert type 'int' to 'string' ? c#4 Commented Nov 13, 2014 at 4:33

1 Answer 1

4

The TableAdapter-method returns an int which is the count of affected records, so how many records were updated. But you are assigning it to a DataTable variable.

int updatedRows = tm.UpdateTeam(AssignedTeam,userName,DateTime.Now,ID);

You either have to

  • load the table again with the appropriate GetData- or Fill(dt) methods from the TableAdapter
  • or update the rows in the table and use tm.Update(modifiedDataTable) instead which will execute the UpdateCommand of the adapater for every row with RowState=Modified.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.