SqlConnection con = new SqlConnection("server=(local);Integrated Security=True;database=varatis");
    SqlParameter[] str = new SqlParameter[]{
      new SqlParameter("@name",SqlDbType.VarChar,50),
      new SqlParameter("@price", SqlDbType.Int),
      new SqlParameter("@image", SqlDbType.Image),
      new SqlParameter("@content", SqlDbType.VarChar,200),
      new SqlParameter("@state", SqlDbType.Int),
      new SqlParameter("@orderid", SqlDbType.Int),
      new SqlParameter("@createdate", SqlDbType.DateTime)};
 
    // ---- 以下修改需要为:
    string sql = "insert into goods(name,price,image,content,state,orderid,createdate)   values  (@name,@price,@image,@content,@state,@orderid,@createdate)";
    str[0].Value = goodModel.Name;
    str[1].Value = goodModel.Price;
    str[2].Value = goodModel.Image;
    // ... 使用上述格式给每个参数赋值 ..., goodModel.Content, goodModel.State, 
    // goodModel.Orderid,goodModel.Createdate;       
    SqlCommand com = new SqlCommand(sql, con);
    com.Parameters.AddRange(str);
    con.Open();
    int result = com.ExecuteNonQuery();
    con.Close();
    return result;
    // ---- OK


本文转载:CSDN博客