D
Devhead
I'm trying to update my dataset back to a table named 'CaseProcedures' in
the sql server DB. I'm getting the following exception when i attempt to run
the line:
SDA.Update(dsChanges,"CaseProcedure");
Exception:
Server was unable to process request ---> Update unable to find table
mapping['CaseProcedure'] or DataTable 'CaseProcedure'
This is strange because i define this in the update statement above. Here's
is my code in its entirety. It is located in a web service:
[WebMethod(true)]
public DataSet UpdateCaseProcedure(DataSet dsChanges)
{
//Get the connection string from web.config file
string TmpConn = ConfigurationSettings.AppSettings["connstring"];
SqlConnection SConn = new SqlConnection(TmpConn);
SqlDataAdapter SDA = new System.Data.SqlClient.SqlDataAdapter();
DataView dv = new DataView(dsChanges.Tables[0]);
//update Case Procedure Table with added rows
dv.RowStateFilter = DataViewRowState.Added;
//StepNbr,Action,ExpectedResult,ActualResult,CaseProcedureStatus.CaseProcedureStatus
Status,Comments, CaseProcedure.CaseProcedureStatus_id,
CaseProcedure.CaseProcedure_id
if (dv.Count > 0)
{
//build insert command
SqlCommand insCmd = new SqlCommand(
"insert into CaseProcedure
(StepNbr,Action,ExpectedResult,ActualResult,Comments)
values(@StepNbr,@Action,@ExpectedResult,@ActualResult,@Comments)",SConn);
//@StepNbr,@Action,@ExpectedResult,@ActualResult,@Comments,@CaseProcedureStatus_id
insCmd.Parameters.Add("@StepNbr", SqlDbType.Int, 4, "StepNbr");
insCmd.Parameters.Add("@Action", SqlDbType.Text, 16, "Action");
insCmd.Parameters.Add("@ExpectedResult", SqlDbType.Text, 16,
"ExpectedResult");
insCmd.Parameters.Add("@ActualResult", SqlDbType.Text, 16, "ActualResult");
insCmd.Parameters.Add("@Comments", SqlDbType.Text, 16, "Comments");
SDA.InsertCommand = insCmd;
}
//update Case Procedure Table with modified rows
dv.RowStateFilter = DataViewRowState.ModifiedOriginal;
if (dv.Count > 0)
{
//build update command
SqlCommand upCmd = new SqlCommand(
"update CaseProcedure set
StepNbr=@StepNbr,Action=@Action,ExpectedResult=@ExpectedResult,ActualResult=@ActualResult,Comments=@Comments
where CaseProcedure_id=@CaseProcedure_id",SConn);
upCmd.Parameters.Add("@StepNbr", SqlDbType.Int, 4, "StepNbr");
upCmd.Parameters.Add("@Action", SqlDbType.Text, 16, "Action");
upCmd.Parameters.Add("@ExpectedResult", SqlDbType.Text, 16,
"ExpectedResult");
upCmd.Parameters.Add("@ActualResult", SqlDbType.Text, 16, "ActualResult");
upCmd.Parameters.Add("@Comments", SqlDbType.Text, 16, "Comments");
upCmd.Parameters.Add("@CaseProcedure_id", SqlDbType.Int, 4,
"CaseProcedure_id");
SDA.UpdateCommand = upCmd;
}
//update Case Procedure Table with deleted rows
dv.RowStateFilter = DataViewRowState.Deleted;
if (dv.Count > 0)
{
//build delete command
SqlCommand delCmd = new SqlCommand(
"delete from CaseProcedure where CaseProcedure_id=@CaseProcedure_id",SConn);
delCmd.Parameters.Add("@CaseProcedure_id", SqlDbType.Int, 4,
"CaseProcedure_id");
SDA.DeleteCommand = delCmd;
}
dv.RowStateFilter = DataViewRowState.None;
SDA.Update(dsChanges,"CaseProcedure"); //this is where the exception
happens
return dsChanges;
}
the sql server DB. I'm getting the following exception when i attempt to run
the line:
SDA.Update(dsChanges,"CaseProcedure");
Exception:
Server was unable to process request ---> Update unable to find table
mapping['CaseProcedure'] or DataTable 'CaseProcedure'
This is strange because i define this in the update statement above. Here's
is my code in its entirety. It is located in a web service:
[WebMethod(true)]
public DataSet UpdateCaseProcedure(DataSet dsChanges)
{
//Get the connection string from web.config file
string TmpConn = ConfigurationSettings.AppSettings["connstring"];
SqlConnection SConn = new SqlConnection(TmpConn);
SqlDataAdapter SDA = new System.Data.SqlClient.SqlDataAdapter();
DataView dv = new DataView(dsChanges.Tables[0]);
//update Case Procedure Table with added rows
dv.RowStateFilter = DataViewRowState.Added;
//StepNbr,Action,ExpectedResult,ActualResult,CaseProcedureStatus.CaseProcedureStatus
Status,Comments, CaseProcedure.CaseProcedureStatus_id,
CaseProcedure.CaseProcedure_id
if (dv.Count > 0)
{
//build insert command
SqlCommand insCmd = new SqlCommand(
"insert into CaseProcedure
(StepNbr,Action,ExpectedResult,ActualResult,Comments)
values(@StepNbr,@Action,@ExpectedResult,@ActualResult,@Comments)",SConn);
//@StepNbr,@Action,@ExpectedResult,@ActualResult,@Comments,@CaseProcedureStatus_id
insCmd.Parameters.Add("@StepNbr", SqlDbType.Int, 4, "StepNbr");
insCmd.Parameters.Add("@Action", SqlDbType.Text, 16, "Action");
insCmd.Parameters.Add("@ExpectedResult", SqlDbType.Text, 16,
"ExpectedResult");
insCmd.Parameters.Add("@ActualResult", SqlDbType.Text, 16, "ActualResult");
insCmd.Parameters.Add("@Comments", SqlDbType.Text, 16, "Comments");
SDA.InsertCommand = insCmd;
}
//update Case Procedure Table with modified rows
dv.RowStateFilter = DataViewRowState.ModifiedOriginal;
if (dv.Count > 0)
{
//build update command
SqlCommand upCmd = new SqlCommand(
"update CaseProcedure set
StepNbr=@StepNbr,Action=@Action,ExpectedResult=@ExpectedResult,ActualResult=@ActualResult,Comments=@Comments
where CaseProcedure_id=@CaseProcedure_id",SConn);
upCmd.Parameters.Add("@StepNbr", SqlDbType.Int, 4, "StepNbr");
upCmd.Parameters.Add("@Action", SqlDbType.Text, 16, "Action");
upCmd.Parameters.Add("@ExpectedResult", SqlDbType.Text, 16,
"ExpectedResult");
upCmd.Parameters.Add("@ActualResult", SqlDbType.Text, 16, "ActualResult");
upCmd.Parameters.Add("@Comments", SqlDbType.Text, 16, "Comments");
upCmd.Parameters.Add("@CaseProcedure_id", SqlDbType.Int, 4,
"CaseProcedure_id");
SDA.UpdateCommand = upCmd;
}
//update Case Procedure Table with deleted rows
dv.RowStateFilter = DataViewRowState.Deleted;
if (dv.Count > 0)
{
//build delete command
SqlCommand delCmd = new SqlCommand(
"delete from CaseProcedure where CaseProcedure_id=@CaseProcedure_id",SConn);
delCmd.Parameters.Add("@CaseProcedure_id", SqlDbType.Int, 4,
"CaseProcedure_id");
SDA.DeleteCommand = delCmd;
}
dv.RowStateFilter = DataViewRowState.None;
SDA.Update(dsChanges,"CaseProcedure"); //this is where the exception
happens
return dsChanges;
}