
con.Open()//打开连接
string sql = string.Format("select * from 你的表名 where 姓名={0} and 电子邮件={1} and 所属部门={2} ",this.textbox1.text,this.textbox2.text,this.textbox3.text)//SQL语句
SqlDataAdapter sad = new SqlDataAdapter(sql, con)//创建查询器
DataSet ds = new DataSet()//创建结果集
sad.Fill(ds)//将结果集填入
con.Close()//关闭连接
this.Datagridview.DataSource = ds.Tables[0]//获取结果集中第一个表,指定数据源!
执行sql:select cardno,name from cardtable where cardno not in (select cardno from cardtable where name='C');嵌套一个子查询来查找包含name包含C的cardno,然后再根据查询条件把cardno不包含的剔除掉。
运行如下:
扩展资料
sql的嵌套查询包括hen多的子查询,in的子查询、带比较运算符的子查询、带any/all的子查询、带exists的子查询以及基于派生表的子查询,这些查询嵌套使用可以达到强大的功能,比如筛选,过滤,排序,去重等等。
参考资料:W3C官网-SQL SELECT 语句
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)