Equivalent in VB.net of VBA rs.Addnew, rs!Field1 = "Bla", rs!Field2 = "Blo", rs.Update ?
Posted on 2014-10-31
I'm converting an Access/VBA/SQLServer app to VB.Net/SQLServer, and in some cases, I have to add one row to existing tables.
In Access there is this very easy and elegant way to fill the fields and create the row by using (rs = recordset name):
rs!Field1 = "Bl1"
rs!Field2 = "Bl2"
rs!Fieldn = "BLn"
which is highly readable and vastly superior to the messy:
"INSERT INTO myTable (field1, field2, ...., fieldn) VALUES ('Bla', 'Blo', ...., 'BLn')
especially when there are a lot of fields and the values are data in forms or from other tables, which leads to unwieldy, never ending concatenations of strings.
When searching for insert examples in .Net, I can only find the "ugly" INSERT INTO ... syntax.
Is there no equivalent to the Access syntax above ?
And I don't want to use a datatable when I have only one row to add, because it seems a huge waste to load the whole existing table in a datatable when only one row is added from time to time.
Thanks for help