System.Data.SqlClient.SqlParameterCollection does not contain a definition for 'AddWithvalue'

StackOverflow https://stackoverflow.com/questions/22900797

  •  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 ?

Was it helpful?

Solution

C# is a case-sensitive language.The method you are trying to call is AddWithValue with capital V not AddWithvalue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top