c# - Does DataSet occupy too much space? -


if wish add information sql server database, must through dataset , dataadapter ?

the idea if database has 1-2 million entries, isn't memory going occupied unnecessary 1-2 mil rows in dataset considering want add 1 row? there alternative ?

you create plain old ado.net parametrized sqlcommand holding simple sql insert statement, , provide parameters, , load data way (nothing needs loaded, doesn't matter how many rows have - work):

string insertstmt = "insert dbo.yourtable(col1, col2, ...., coln) " +    "values(@value1, @value2, ...., @valuen)";  using(sqlconnection _con = new sqlconnection(-your-connection-string-here)) using(sqlcommand _cmdinsert = new sqlcommand(insertstmt, _con))     {    // define parameters query    _cmdinsert.parameters.add("@value1", sqldbtype.int);     .......     // set values    _cmdinsert.parameters["@value1"].value = 4711;    .....     _con.open();    int rowsinserted = _cmdinsert.executenonquery();    _con.close(); }   

if have multiple rows insert, loop on e.g. list of objects, set values our _cmdinsert each object, , execute _cmdinsert.executenonquery() each row.

of course, if use orm (nhibernate, linq-to-sql, entity framework), work might infinitely easier - insert new objects collection , save them - orm deal nitty-gritty details (and code showed above , execute - more or less).


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -