日期:2014-05-18 浏览次数:20883 次
string commtext1= "SELECT Mysheet.*,Mysheetout.* FROM Mysheet,Mysheetout WHERE Mysheet.Col1 LIKE " + "'%" + 产品1 + "%'" + " AND Mysheetout.Col1 LIKE " + "'%" + 产品1 + "%'"; SQLiteDataAdapter thisadapter = new SQLiteDataAdapter(commtext1, conn); DataSet thisdataset = new DataSet(); thisadapter.Fill(thisdataset); dataGridView1.DataSource = thisdataset.Tables[0];
select * from Mysheet,MysheetOut where Mysheet.Col1='产品1' and Mysheet.col1=MysheetOut.col1
------解决方案--------------------
写错了,用下面的代码
SqlConnection con = new SqlConnection("数据库连接串"); con.Open(); string sql = string.Format(@"select a.col1,b.col2,b.col3 from mysheet as a inner join mysheetout as b on a.col1=b.col1 where (a.col2={0} or a.col3={0} or a.col4={0} or a.col5={0} or a.col6={0} or a.col7={0} or a.col8={0} or a.col9={0} or a.col10={0})",textBox1.Text.Trim()); SqlCommand cmd = new SqlCommand(sql, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet dst = new DataSet(); sda.Fill(dst); con.Close(); dataGridView1.DataSource = dst.Tables[0];
------解决方案--------------------
LZ主要是需要个查询语句
select a.productName,b.col1,b.col2,b.col3 (select a.productName,a.productCode from(select col1 as productName,col2 as productcode from mysheet
uion all
select col1,col3 from mysheet
union all
………
select col1,col10 from mysheet
) a where a.productCode=控件名.Text.tostring()) a left join mysheetout b on a.productCode=b.col1
LZ如果需要自己完善语句吧,给LZ参考下