终于解决了,网上很多教程 害人不浅啊,用了一大堆垃圾代码。
我的程序:
SqlDataSource2.SelectCommand = "Select count(*) from [TBFiscalCalendar] where YearMonth = '" + NewYM + "'";
SqlConnection myCon=new SqlConnection(SqlDataSource2.ConnectionString);
SqlCommand myCom = new SqlCommand(SqlDataSource2.SelectCommand,myCon);
myCon.Open();
int countD=(int)myCom.ExecuteScalar();
myCon.Close();
if (countD == 0)
{
SqlDataSource2.InsertCommand = "INSERT INTO [TBFiscalCalendar] ([YearMonth]) VALUES ("+NewYM+")";
SqlDataSource2.Insert();
}
SqlDataSource2是非棒定数据源。只是一个为了判断和插入记录的
本文介绍了解决SQL中判断记录是否存在并进行插入的问题,通过使用SqlConnection、SqlCommand等组件,实现了对[TBFiscalCalendar]表中特定年月数据的检查及插入。

被折叠的 条评论
为什么被折叠?



