日期:2014-05-19  浏览次数:20782 次

Visual C# 中如何写SQL语句进行有条件的查询?
代码如下:

using   System;
using   System.Collections.Generic;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Text;
using   System.Windows.Forms;

namespace   SQLSearch
{
        public   partial   class   Form1   :   Form
        {
                public   Form1()
                {
                        InitializeComponent();
                }

                private   void   Form1_Load(object   sender,   EventArgs   e)    
                {
                       

                }

                private   void   button1_Click(object   sender,   EventArgs   e)
                {
                                                                                      //查询tby07中所有信息
                        this.tby07TableAdapter.Fill(this.chisbzDataSet.tby07);
                }

                private   void   button3_Click(object   sender,   EventArgs   e)
                {
                        this.Close();
                }

                private   void   button2_Click(object   sender,   EventArgs   e)
                {
                        string   sql;                                         //查询符合输入条件的信息
                        sql   =   "select   *   from   tby07   where   dmmc= ' "+textBox1.Text+ "   '   ";
                       
                        /////接下来如何写   才能在dataGridView1中显示查询结果?
                }
        }
}

各位帮忙补充下……   谢谢!!!

------解决方案--------------------
接下来 还是用Adapter.Fill(ds);
然后再将dataGridView1的数据源制定到这个ds就ok了
------解决方案--------------------