string str1="select code,name,sex from sometable1";
SqlDataAdapter sda1=new SqlDataAdapter(str1,myConnection);
DataSet ds1=new DataSet();
sda1.Fill(ds1,"somtable1");
sda1.dispose(); //就是下面的 where 条件不知道该如何判断,code,name,sex 三个字段必须跟ds1里的三个字段的
//值一样,不晓得该怎么样进行比较。
string str2=" select * "+
" from someotable2 "+
" where code="+ds1.Tables["sometable1"].Columns["code"]+
" and name="+ds1.Tables["sometable1"].Columns["name"]+
" and sex="+ds1.Tables["sometable1"].Columns["sex"]+
SqlDataAdapter sda2=new SqlDataAdapter(str2,myConnection);
DataSet ds2=new DataSet();
sda2.Fill(ds2,"sometable2");
myDataGrid.DataSource=ds2.Tables["sometable2"].DefaultView;
myDataGrid.DataBind();
sda2.Dispose();
myConnection.Close();中间的 where code=... and name=... and sex=..."是从ASP里迁过来的,不知道是否对。
大侠们,指点指点吧,谢过了先。
SqlDataAdapter sda1=new SqlDataAdapter(str1,myConnection);
DataSet ds1=new DataSet();
sda1.Fill(ds1,"somtable1");
sda1.dispose(); //就是下面的 where 条件不知道该如何判断,code,name,sex 三个字段必须跟ds1里的三个字段的
//值一样,不晓得该怎么样进行比较。
string str2=" select * "+
" from someotable2 "+
" where code="+ds1.Tables["sometable1"].Columns["code"]+
" and name="+ds1.Tables["sometable1"].Columns["name"]+
" and sex="+ds1.Tables["sometable1"].Columns["sex"]+
SqlDataAdapter sda2=new SqlDataAdapter(str2,myConnection);
DataSet ds2=new DataSet();
sda2.Fill(ds2,"sometable2");
myDataGrid.DataSource=ds2.Tables["sometable2"].DefaultView;
myDataGrid.DataBind();
sda2.Dispose();
myConnection.Close();中间的 where code=... and name=... and sex=..."是从ASP里迁过来的,不知道是否对。
大侠们,指点指点吧,谢过了先。
str2+=" from someotable2 ";
str2+=" where code="+"'"+ds1.Tables["sometable1"].Columns["code"].ToString()+"'";
str2+=" and name="+"'"+ds1.Tables["sometable1"].Columns["name"].ToString()+"'";
str2+=" and sex="+"'"+ds1.Tables["sometable1"].Columns["sex"].ToString()+"'";
string str2 ="select * from someotable2 where code='{0}' and name='{1]' and sex='{2}'";
str2 =string.Format(str2,ds1.Tables["sometable1"].Columns["code"],ds1.Tables["sometable1"].Columns["name"],ds1.Tables["sometable1"].Columns["sex"]);
" select * "+
" from someotable2 "+
" where code='"+ds1.Tables["sometable1"].Rows[i].Columns["code"].ToString()+"'"+
" and name='"+ds1.Tables["sometable1"].Rows[i].Columns["name"].ToString()+"'"+
" and sex="+ds1.Tables["sometable1"].Rows[i].Columns["sex"].ToString()
" select * "+
" from someotable2 "+
" where code='"+ds1.Tables["sometable1"].Rows[i]["code"].ToString()+"'"+
" and name='"+ds1.Tables["sometable1"].Rows[i]["name"].ToString()+"'"+
" and sex="+ds1.Tables["sometable1"].Rows[i]["sex"].ToString()
单引号是做什么用的? 我试过了,不行。