indevnow
unread,Apr 7, 2011, 2:24:14 PM4/7/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mybatisnet-user
Hi,
I would like to be able to insert multiple records into a MSSQL 2008
table using the following query format:
INSERT INTO [ITEM] (Name, Type, Description)
VALUES (“Gummy”, “Candy”, “taste sweet”), (“Lemon”, “Fruit”, “taste
sour”)
I tried the following:
<insert id="InsertItemCollection"
parameterClass="ItemFactory.models.Contract.ItemContextBatch" >
INSERT INTO [User] (Name, Type, Description)
VALUES
<iterate property="ItemContextCollection"
open="(" close=")" conjunction=",">
#ItemContextCollection [].ItemContext.Name#,
#ItemContextCollection [].ItemContext.Type#, #ItemContextCollection
[].ItemContext.Description#
</iterate>
</insert>
However, this complains that I don’t have the same number of values as
columns:
"There are fewer columns in the INSERT statement than values specified
in the VALUES clause. The number of values in the VALUES clause must
match the number of columns specified in the INSERT statement."
The query works fine when I execute it from MSSQL server management
studio. Am I note using the iterate tag correct?
Sincerely,
indevnow