===dataset中怎样按条件查找===
一dataset中有一表dmpcs,其中有两个字段(no,name),怎样找到符合编号的name值?谢谢。 问题点数:20、回复次数:8Top
1 楼saucer(思归)回复于 2003-09-03 08:50:19 得分 10
DataRow[] drs = DataSet1.Tables["dmpcs"].Select("no= 'abc'");
if (drs.Length > 0)
{
Response.Write((string)drs[0]["name"]);
}Top
2 楼nchln(打倒传奇)回复于 2003-09-03 08:55:27 得分 5
DataSet.tables["dmpcs"].select("name='"+变量+"'"),返回数据行。Top
3 楼chenam(江南鱼米之乡)回复于 2003-09-03 09:17:12 得分 0
protected DataSet mydroupdr=new DataSet();
----------
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 67: {
行 68:
行 69: DataRow[] drs = mydroupdr.Tables["dmpcs"].Select("name="+DropDownList1.SelectedItem.ToString().Trim());//停在这一行上
行 70: if (drs.Length > 0)
行 71: {
Top
4 楼yewei4u(yewei)回复于 2003-09-03 09:17:29 得分 5
DataSet.Table["dmpcs"].Select()Top
5 楼chenam(江南鱼米之乡)回复于 2003-09-03 10:03:59 得分 0
哪里错了?Top
6 楼saucer(思归)回复于 2003-09-03 10:18:52 得分 0
System.Diagnostics.Debug.Assert(mydroupdr.Tables["dmpcs"] != null);
System.Diagnostics.Debug.Assert(DropDownList1.SelectedItem != null);
System.Diagnostics.Debug.Assert(DropDownList1.SelectedItem.Value != null);
System.Diagnostics.Debug.Assert(DropDownList1.SelectedItem.Value != String.Empty);
DataRow[] drs = mydroupdr.Tables["dmpcs"].Select("name='"+DropDownList1.SelectedItem.Value.ToString().Trim() +"'");
Top
7 楼chenam(江南鱼米之乡)回复于 2003-09-03 10:49:43 得分 0
还是不行,不知道为什么.Top
8 楼chenam(江南鱼米之乡)回复于 2003-09-03 10:54:03 得分 0
public class dstj : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Table Tablejb;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.Button Button1;
protected DataSet mydroupdr=new DataSet();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!Page.IsPostBack)
{
SqlConnection myconn=new SqlConnection("server=(local);database=zzrkpcs;uid=sa;pwd=");
SqlDataAdapter mydroupcmd=new SqlDataAdapter("select dmpcs_tab.dmmc,dmpcs_tab.dmzm from dmpcs_tab where dmzm like '330282%' order by substring(dmzm,1,6)",myconn);
mydroupcmd.Fill(mydroupdr,"dmpcs");
DropDownList1.DataSource=mydroupdr.Tables["dmpcs"];
DropDownList1.DataValueField="dmmc";
DropDownList1.DataTextField="dmmc";
DropDownList1.DataBind();
DropDownList1.Items.Add("请选择");
}
}
----------
private void Button1_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Debug.Assert(mydroupdr.Tables["dmpcs"] != null);
System.Diagnostics.Debug.Assert(DropDownList1.SelectedItem != null);
System.Diagnostics.Debug.Assert(DropDownList1.SelectedItem.Value != null);
System.Diagnostics.Debug.Assert(DropDownList1.SelectedItem.Value != String.Empty);
DataRow[] drs = mydroupdr.Tables["dmpcs"].Select("dmmc='"+DropDownList1.SelectedItem.ToString().Trim()+"'");
if (drs.Length > 0)
{
string dmpcs_dmzm =(string)drs[0]["dmzm"];
}
.....
}
}Top



