Insert Dictionary into Database

Hi ,

Can anyone help me to insert a dictionary of values into database.

  1. I build a dictionary with 4 key value pairs . Now I have this collection.
  2. Im want to use execute Query to insert the values into DB.

Can anyone help me here


@pkodali - welcome to community!

in your query - you can directly get the values from the dictionary like dictonaryVariable(“KEYNAME”).ToString

sample for select -

select * from table
where col1 =‘“+vrDict(“key1”).ToString+”’ and col2 =‘“+vrDict(“key2”).ToString+”’

sample for insert statement -

insert into xyz (col1,col2,col3) values(‘“+vrDict(“key1”).ToString+”’ , ‘“+vrDict(“key2”).ToString+”’ , ‘“+vrDict(“key3”).ToString+”’ )

Do you mean each value pair as one record in the DB (in your case 4 records)?


I want to insert dynamically , both column names and Values . Dont want to hardcode column names

you can do a for each loop with dictionary ( argument type as System.Collections.Generic.KeyValuePair<System.String, System.String>) and build two variable 1 - columns , 2- values

after foreach you can write slike - insert into table (variable1) vales(variable2)

Still not clear what you want to achieve.
What your DB table looks like?
What do you want to insert - key and value, just key?