When executing command.Prepare() I have “SqlCommand.Prepare method requires all parameters to have an explicitly set type” error

自闭症网瘾萝莉.ら 提交于 2019-12-04 06:35:44

问题


I have the following statements:

SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["DataBaseName"]);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "update Table1 set data = @data where id = @id";
cmd.Parameters.AddWithValue("@data", SqlDbType.VarChar).Value =  data;
cmd.Parameters.AddWithValue("@id", SqlDbType.Int).Value =  id;
cmd.CommandType = CommandType.Text;

try
{
    DataSet ds = new DataSet();
    con.Open();
    cmd.Prepare();
    cmd.ExecuteNonQuery();
    return true;
}

When executing cmd.Prepare() I have an error SqlCommand.Prepare method requires all parameters to have an explicitly set type

I read some answers here, but looks like I did as described here but still have the same problem.

What am I missing?

来源:https://stackoverflow.com/questions/36554082/when-executing-command-prepare-i-have-sqlcommand-prepare-method-requires-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!