How can I script object data in SMO?

Hi could somebody give a suggestion or post some example on how I can script table Data

Suppose I have a Customer Table I need to produce something like :

INSERT INTO [dbo].[Customers] ([CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City], [Region], [PostalCode], [Country], [Phone], [Fax])

VALUES('ALFKI', 'Alfreds Futterkiste', 'Maria Anders', 'Sales Representative', 'Obere Str. 57', 'Berlin', null, '12209', 'Germany', '030-0074321', '030-0076545')


INSERT INTO [dbo].[Customers] ([CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City], [Region], [PostalCode], [Country], [Phone], [Fax])

VALUES('ANATR', 'Ana Trujillo Emparedados y helados', 'Ana Trujillo', 'Owner', 'Avda. de la Constitucion 2222', 'Mexico D.F.', null, '05021', 'Mexico', '(5) 555-4729', '(5) 555-3745')

Any suggestions

thanks a lot in advance



Answer this question

How can I script object data in SMO?

  • arclsvg

    SMO is an object model for managing database objects, not data. Your best bet is to use ADO.Net and pass your DML statements that way.

  • pollie32

    Actually, the scripter object is a great tool to generate T-SQL scripts from the object changes you make in your SMO code.

    Good luck with your project.



  • al_cenov

    Hi ,Thanks for your reply.

    Not knowing smo well I thought that the scripterObject might do the job.

    I will get a dataset and loop through it and append fields accordingly.

    Thanks


  • How can I script object data in SMO?