您的位置:程序门 -> .net技术 -> c#



查询问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


查询问题[已结贴,结贴人:sxlcom]
发表于:2007-01-22 16:06:38 楼主
请问大家一个问题,如果一个表中有5个字段,我用了5个文件框作为查询条件来查询数据,但现在出现一个问题,如果txt_wjbm.text   不输入条件,那么   执行查询时会提示错误,有多于的 'and '
部分代码如下:
  searchstring= "where ";
                                        if   (txt_wjbm.text   !=   " ")
                                                searchstring   =   " "+searchstring+ "   weijibianma= ' "   +   txt_wjbm.text   +   " '   ";
                                                                                       

                                        if   (txt_dwmc.text   !=   " ")
                                                searchstring   =   "   "+searchstring+ "   and   nashuirenjc= ' "   +   txt_dwmc.text   +   " ' ";

                                          if   (txt_dh.text   !=   " ")
                                                  searchstring   =   " "   +   searchstring   +   "and   dianhua= ' "   +   txt_dh.text   +   " '   ";
                                                     
                                        if     (txt_youxiaoriqi.text   !=   " ")
                                                searchstring   =   "   "   +   searchstring   +   "and   youxiaoriqi <= ' "   +   convert.todatetime(txt_youxiaoriqi.text)   +   " '   ";
                                                                       
                                        if   (txt_cjr.text   !=   " ")
                                                searchstring   =   "   "   +   searchstring   +   "and   chuanjianren= ' "   +   txt_cjr.text   +   " '   ";
发表于:2007-01-22 16:09:411楼 得分:20
这样改,别的不变

searchstring= "where   1   =   1   ";
if   (txt_wjbm.text   !=   " ")
searchstring   =   " "+searchstring+ "and   weijibianma= ' "   +   txt_wjbm.text   +   " '   ";
发表于:2007-01-22 16:31:042楼 得分:0
非常感谢
发表于:2007-01-22 16:34:393楼 得分:0
是楼上这样的!我都是这么做的   !呵呵


快速检索

最新资讯
热门点击