C# - Inserting DataSet that contains relational DataTables into Sql Server -



C# - Inserting DataSet that contains relational DataTables into Sql Server -

hi have dataset in c# contains 3 datatables. 2 of tables: summarylocal_bands , summarylocal_averages contain fk relationship pk in 3rd table: summarylocal. tables in sql server have same structure, columns, relationships, etc tables in dataset. lets add together rows datatables in dataset contain data. want insert rows sql server tables (which contain same construction datatables in dataset noted above). how hard accomplish , how accomplish it? or smarter accomplish way?

is seems want persist changes on datatables it's underlying tables in database..can't create connection database , create insert statement?...

try creating method have next commands below: (note: it's skeleton of commands need do, fill them according settings)

string connectionstring = "your_connection_string"; sqlconnection con = new sqlconnection(connectionstring); seek { con.open(); string query = "insert statement"; using (sqlcommand cmd = new sqlcommand(query, con)) { cmd.parameters.addwithvalue("@some_parameter", "value_of_some_parameter"); cmd.executenonquery(); } } grab (exception) { throw; }

or, if datatables somehow not connected database, can still utilize above method looping through contents of datatable.

c# sql-server datatable insert dataset

Comments

Popular posts from this blog

javascript - I need to update the text of a paragraph by inline edit -

javascript - THREE.js reposition vertices for RingGeometry -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -