Ignoring the hazards of manually building an SQL statement, you should be able to create the desired string as follows:
string addText =
string.Join(", ", ld.Cast<DictionaryEntry>()
.Select(de => Escape(de.Key) + "=" + Escape(de.Value))
.ToArray());
Example:
ListDictionary ld = ListDictionary
{
{ "Key1", "Value1" },
{ "Key2", "Value2" },
{ "Key3", "Value3" },
};
then the Select
in the code above would transform this to
string[] temp = new string[]
{
"Key1=Value1",
"Key2=Value2",
"Key3=Value3",
};
and string.Join
would join these strings together to
string addText = "Key1=Value1, Key2=Value2, Key3=Value3";
But you really should use a library that does the database access for you. Manually building SQL statements is error-prone and can be even dangerous .