ExecuteNonQuery requires the command to have a transaction error in my code

You need to change this line SqlCommand cmd = new SqlCommand(“update Contact_Info set CustInfo=” + ds.GetXml() + ” WHERE Customer_ID=” + a + “”, scon); in this way SqlCommand cmd = new SqlCommand(“update Contact_Info set CustInfo=” + ds.GetXml() + ” WHERE Customer_ID=” + a + “”, scon, sqlTrans); The error message states exactly the problem. … Read more

How to convert Dictionary to Dictionary in c#

Use the ToDictionary method: Dictionary<string, string> dString = dObject.ToDictionary(k => k.Key, k => k.Value.ToString()); Here you reuse the key from the original dictionary and you convert the values to strings using the ToString method. If your dictionary can contain null values you should add a null check before performing the ToString: Dictionary<string, string> dString = … Read more

Get Max value from List

Assuming you have access to LINQ, and Age is an int (you may also try var maxAge – it is more likely to compile): int maxAge = myTypes.Max(t => t.Age); If you also need the RandomID (or the whole object), a quick solution is to use MaxBy from MoreLinq MyType oldest = myTypes.MaxBy(t => t.Age);

How can I evaluate C# code dynamically?

Using the Roslyn scripting API (more samples here): // add NuGet package ‘Microsoft.CodeAnalysis.Scripting’ using Microsoft.CodeAnalysis.CSharp.Scripting; await CSharpScript.EvaluateAsync(“System.Math.Pow(2, 4)”) // returns 16 You can also run any piece of code: var script = await CSharpScript.RunAsync(@” class MyClass { public void Print() => System.Console.WriteLine(1); }”) And reference the code that was generated in previous runs: await script.ContinueWithAsync(“new … Read more