C#
is a case-sensitive
language.The method you are trying to call is AddWithValue
with capital V
not AddWithvalue
.
System.Data.SqlClient.SqlParameterCollection does not contain a definition for 'AddWithvalue'
-
28-06-2023 - |
Question
public static DataTable SqlDataTable(string sql, IDictionary<string, object> values)
{
using (SqlConnection conn = new SqlConnection(GetConnectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
conn.Open();
foreach (var item in values)
{
cmd.Parameters.AddWithvalue("@" + item.Key, item.Value); // error
}
.......
........
Error 4 'System.Data.SqlClient.SqlParameterCollection' does not contain a definition for 'AddWithvalue' and no extension method 'AddWithvalue' accepting a first argument of type 'System.Data.SqlClient.SqlParameterCollection' could be found (are you missing a using directive or an assembly reference?)
Why I get this error ?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow