Vipin
Vipin

Reputation: 261

Cannot implicitly convert type 'int' to 'System.Data.DataTable'

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

Upvotes: 2

Views: 4795

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460288

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.

Upvotes: 4

Related Questions