SMO Transfering specific rows from specific tables?

  • In many situations, I just want to grab one or two rows from a table and script out the inserts. It would be nice if SMO did this for me automatically, including handling whether to generate "set identity_insert [schema].[table_name] on/off" lines.

    I can't use the traditional way to dump table data:

    ScriptingOptions.ScriptData = true

    This option scripts out EVERYTHING. I just want one row, e.g. the row where a PK equals 0.

    What's the best way to do this?

  • Hello,

    I am sorry , but , with my poor english, i am not sure to have fully understood your question.

    I am using SMO since the release of SQL Server 2005 SP2 ( before SMO was often incomplete or with bugs ).

    To get the results of a query ( SElECT mainly ) , i am relying on the SqlClient namespace ( so .Net Framework ) and for the SqlConnection necessary to create a SqlCommand , i get it from the SqlConnectionObject property of Server.ConnectionContext.

    I have some doubts to have understood your hypothesis about primary keys with a value of 0. Please, could you tell us whether you want to create a primary key on a column having already values ? If yes, you cannot create a primary key on a column if you have several rows with the same value.

    But, it is possible that i have not understood your question ( usually, i can translate english in french, but french into english , really difficult for me and i hope you will excuse me ).

    Have a nice day

  • It's ok. I solved the problem by avoiding it. Using SMO was an experiment and a bad idea for this problem. Wrong tool for the job.

  • Hi, Can you provide the script for insert script for all table data? Thanks

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply