Bulk Insert using asp.net with xml with sql Queries


This Articles explaining about the bulk insert using xml nodes. it convert our input parameter as single xml node and it save the xml node into our sql data base so it will reduce the number of Database hit and increase the performance.

Step:1

The for loop which contains the item name so the item name is get it from for loop and save into the xml node


for(int i = 30; i < Type.Count(); i++)
{

//Get Item Name
string itemName = ItemName[i];

sb.Append("");

break;
}
}
}

sb.Append("");

//Insert Method

Place your insert method here and pass sb.Tostring() as parameter

using(ItemInfo item = new ItemInfo())
{
item .InsertItems(sb.ToString());
}


Step :2

Please add following Query into your Sql stored procedure

CREATE PROCEDURE [dbo].[InsertItems]
-- Add the parameters for the stored procedure here
@xml xml

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
INSERT INTO Items
(
ItemName
)
SELECT
TempSwot.Item.value('@ItemName', 'VARCHAR(150)')
FROM @xml.nodes('/root/row') AS TempSwot(Item)
END

Now its inserted Bulk amount of data at single attempt..


Attachments

  • Bulk Insert (43103-20546-bulkinsert.txt)
  • Comments

    No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: