本文介绍了如何与数据库值进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有桌子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();更多推荐
如何与数据库值进行比较
发布评论