Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my service, I have a method below

C#
public bool WriteDataTable(DataTable dt)
        {
            try
            {               
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["StrConnection"].ToString());
                SqlCommand cmd = new SqlCommand("INSERT dbo.VPG02(column list) SELECT column list FROM @dt;", connection);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter tvparam = cmd.Parameters.AddWithValue("@dt", dt);
                tvparam.SqlDbType = SqlDbType.Structured;
                cmd.ExecuteNonQuery();
            }
            catch
            {
                return false;
            }
            return true;
        }


I have call this method on form

C#
MyService.WriteDataTable(dt);


It throw the error below

There was an error in serializing body of message InsertRequest: 'There was an error generating the XML document.'.  Please see InnerException for more details.


I don't know what happen, please help me to fix this problem? thanks and best regards!

What I have tried:

I have searched google, but it can't help me
Posted
Comments
TVP COMPANY 31-Jul-16 5:50am    
Sorry, I paste wrong.
This is the update :

SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["StrConnection"].ToString());
SqlCommand cmd = new SqlCommand("dbo.[InsertTable]", connection);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter tvparam = cmd.Parameters.AddWithValue("@MyTable", dt);
tvparam.SqlDbType = SqlDbType.Structured;
cmd.ExecuteNonQuery();


And this is my store procedure :

ALTER PROCEDURE [dbo].[InsertTable]
(
@MyTable dbo.EMCIDetail Readonly
)

AS
BeGIN
insert into [dbo].B200 select * from @MyTable
END
Patrice T 31-Jul-16 9:01am    
Use Improve question to update your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900