如何检查记录是否存在,更新和插入

编程入门 行业动态 更新时间:2024-10-22 18:31:03
本文介绍了如何检查记录是否存在,更新和插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在运行模式下如下 从日期日历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 A

When 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 A

When 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)

更多推荐

如何检查记录是否存在,更新和插入

本文发布于:2023-10-25 08:50:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1526482.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:新和   是否存在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!