在运行模式下如下 从日期日历1 在表格记录中如下
Schdate课程职员有效 8月14日MFA BJR A 8月14日EFA RPK A当我点击发件人日期时我想检查所选日期记录是否在数据库中。 假设用户选择calendar1中的28 aug 14,检查数据库中是否存在选定的28 aug 14记录。 如果显示所选日期记录的消息就在那里。 假设所选日期记录是否要激活'A'在'D'想要提升 然后插入记录后。 for that怎么样我在asp中使用c验证# 问候, Narasiman P.
解决方案在表中记录如下
Schdate课程职员有效 8月14日MFA BJR A 8月14日EFA RPK A当我点击发件人日期时,我想检查所选日期记录是否在数据库中。 要检查记录是否存在,请使用查询:
SqlCommand cmd; SqldataAdapter adpt = new SqlDatAdapter( select从表名中计数(*),其中Schdate = '28 -Aug-14',cn); DataSet ds = new DataSet(); adpt.Fill(ds); if (ds.Tables [ 0 ]。Rows.Count > 0 ) { Response.Write( 记录存在); for ( int i = 0 ; i< ds.tables [ 0 ]。rows.count; i ++)> { cmd = new SqlCommand( update tablename set Active ='D',其中Staff =' + ds.Tables [ 0 ]。行[i] [ 2 ]。ToString()+ ',cn) ; cn.Open(); cmd.ExeceuteNonQuery(); cn.Close(); cmd.Dispose(); } } else { Response.Write( 记录不存在); }
要检查Db中是否存在记录,您可以使用简单的'if exists'SQL 要插入或更新记录,您可以进行简单的更新..在哪里或简单的插入(您已经检查过是否存在)
In run mode as follows From date calendar1 In Table record as follows
Schdate course Staff Active 28 Aug 14 MFA BJR A 29 Aug 14 EFA RPK AWhen i click the From date i want to check for selected date record is there in the database. suppose user select the 28 aug 14 in the calendar1, check whehter for selected 28 aug 14 record is there in the database. if there shows the message for the selected date records is there. suppose for selected date record is there want to Active 'A' in to 'D' want to upate Then after inserting the record. for that how can i validate in asp using c# Regards, Narasiman P.
解决方案 In Table record as follows Schdate course Staff Active 28 Aug 14 MFA BJR A 29 Aug 14 EFA RPK AWhen i click the From date i want to check for selected date record is there in the database. To check the existence of the record use the query:
SqlCommand cmd; SqldataAdapter adpt = new SqlDatAdapter("select count(*) from tablename where Schdate='28-Aug-14'",cn); DataSet ds = new DataSet(); adpt.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { Response.Write("Record Exists"); for (int i=0;i<ds.tables[0].rows.count;i++)> { cmd = new SqlCommand("update tablename set Active='D' where Staff = '" + ds.Tables[0].Rows[i][2].ToString() + "'",cn); cn.Open(); cmd.ExeceuteNonQuery(); cn.Close(); cmd.Dispose(); } } else { Response.Write("Record Not Exists"); } To check if a record exists in the Db you can use a simple 'if exists' SQL To insert or update records you can do a simple Update ..Where or a simple Insert (you've already checked if it exists)更多推荐
如何检查记录是否存在,更新和插入
发布评论