日期:2014-05-17 浏览次数:20756 次
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("number",typeof(string)),
new DataColumn("age",typeof(Int32))
});
DataRow dr = null;
dr = dt.NewRow();
dr["number"] = "2013100";
dr["age"] = 1;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["number"] = "2013200";
dr["age"] = 2;
dt.Rows.Add(dr);
int a = 0;
string inputNumber = "2013200";
DataRow[] drs = dt.Select("number='" + inputNumber + "'");
if (drs != null && drs.Length > 0)
{
foreach (DataRow item in drs)
{
a = Convert.ToInt32(item["age"]);
}
}
MessageBox.Show(a + "");