您的位置:首页 > 编程语言 > ASP

在asp.net2.0中手动写"添加"事件、判断重复--青蛙非王子(lostfrog)

2006-05-09 14:07 615 查看
终于解决了,网上很多教程 害人不浅啊,用了一大堆垃圾代码。

我的程序:

        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是非棒定数据源。只是一个为了判断和插入记录的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp.net insert
相关文章推荐