如何与数据库值进行比较

编程入门 行业动态 更新时间:2024-10-24 14:26:28
本文介绍了如何与数据库值进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有桌子billentry 列是token_no ppo_no billdate 2 1138 4/6/2014 3 11951 4/6/2014 现在来自combobox我再次选择ppo_no 1138因此它将显示1138已经在4/6/​​2014的数据库中

解决方案

检查这些: 1. vb_combobox [ ^ ] 2. Visual-Basic-Code-Snippet-Check-Record-Exists-in-SQL-Server-Database [ ^ ] 尝试这个.. :)

string ppo_no = 设置ppo_no值; // E.G。 1138 string billDate = 设置billdate; // E.G。 2014年4月6日 字符串 DeleteStr = select * from Tablename其中ppo_no = + ppo_no + 并转换(varchar,billdate,106)= convert(varchar, + billDate + ,106); // 您可以随意设置日期格式 SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings [ ConnectionstringName]的ConnectionString); SqlCommand sql_cmd = new SqlCommand(DeleteStr,cn); cn.Open(); DataTable dtGetData = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(sql_cmd); da.Fill(dtGetData); if (dtGetData.Rows.Count > 0 ) { // 数据已经存在..:) } else { // 数据不存在。 :) } cn.Close(); cn.Dispose(); sql_cmd.Dispose();

i have table billentry column is token_no ppo_no billdate 2 1138 4/6/2014 3 11951 4/6/2014 now from combobox i have select ppo_no again 1138 so it will show 1138 is already in database in 4/6/2014

解决方案

Check these out: 1. vb_combobox[^] 2. Visual-Basic-Code-Snippet-Check-Record-Exists-in-SQL-Server-Database[^]

try this.. :)

string ppo_no = "Set ppo_no value"; //E.G. 1138 string billDate = "Set billdate"; //E.G. 4/6/2014 string DeleteStr = "select * from Tablename where ppo_no="+ppo_no+" and convert(varchar,billdate,106)=convert(varchar,"+billDate+",106)"; //You can set date format whatever you want SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionstringName"].ConnectionString); SqlCommand sql_cmd = new SqlCommand(DeleteStr, cn); cn.Open(); DataTable dtGetData = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(sql_cmd); da.Fill(dtGetData); if (dtGetData.Rows.Count > 0) { //Data already exists.. :) } else { //Data is not exists. :) } cn.Close(); cn.Dispose(); sql_cmd.Dispose();

更多推荐

如何与数据库值进行比较

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

发布评论

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

>www.elefans.com

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