如果记录存在,我正在尝试构建更新语句,否则插入新记录。我有一个可以使插入正常的 DAL,但现在我需要为现有案例添加更新。我有这个用于插入的工作代码:
public static void saveArticle(DateTime mtime, int mid, string mname, double homeodds, double awayodds, double drawodds)
{
var culture = CultureInfo.GetCultureInfo("sv-SE");
var dateTimeInfo = DateTimeFormatInfo.GetInstance(culture);
var dateTime = DateTime.Today;
int weekNumber = culture.Calendar.GetWeekOfYear(dateTime, dateTimeInfo.CalendarWeekRule, dateTimeInfo.FirstDayOfWeek);
string mroundY = dateTime.Year.ToString();
string mroundW = weekNumber.ToString();
string mround = mroundY + mroundW;
//Console.WriteLine(mround);
SqlCommand saveArticle = new SqlCommand("Insert Into gameTB(mround, mtime, mid, mname, homeodds, awayodds, drawodds) VALUES (@mround,@mtime,@mid,@mname,@homeodds,@awayodds,@drawodds)");
saveArticle.Parameters.Add("@mround", SqlDbType.Int).Value = mround;
saveArticle.Parameters.Add("@mtime", SqlDbType.DateTime).Value = mtime;
saveArticle.Parameters.Add("@mid", SqlDbType.Int).Value = mid;
saveArticle.Parameters.Add("@mname", SqlDbType.VarChar, 255).Value = mname;
saveArticle.Parameters.Add("@homeodds", SqlDbType.Float).Value = homeodds;
saveArticle.Parameters.Add("@awayodds", SqlDbType.Float).Value = awayodds;
saveArticle.Parameters.Add("@drawodds", SqlDbType.Float).Value = drawodds;
DAL.ExecuteNonQuery(saveArticle);
}
阅读此论坛帖子后,我尝试添加 IF 语句,但它不适用于我使用的逻辑。
如何使用已有的 else insert 命令完成更新?