If I wish to add some information to my SQL Server database, must I do it through a DataSet and a DataAdapter ?
The idea is that if my database has 1-2 million entries, isn’t my memory going to be occupied unnecessary with the 1-2 mil rows in the DataSet considering that I want to add only one row? Is there an alternative ?
You could always create a plain old ADO.NET parametrized
SqlCommandholding a simple SQL INSERT statement, and provide parameters, and load the data that way (nothing needs to be loaded, doesn’t matter how many rows you already have – it will just work):If you have multiple rows to insert, you could loop over e.g. a list of objects, set the values for our
_cmdInsertfor each object, and execute the_cmdInsert.ExecuteNonQuery()for each row.Of course, if you use something like an ORM (NHibernate, Linq-to-SQL, Entity Framework), that work might get infinitely easier – just insert new objects into your collection and save them – the ORM will deal with all the nitty-gritty details (and basically do this code I showed above and execute it – more or less).