dataset新添加的列为何得不到值?
DataSet ds = new DataSet();
str="select content,title,read_amount,[time],id,pic from news where type='"+s+"' order by id asc
OleDbDataAdapter adapter = new OleDbDataAdapter(str, myConnection);
adapter.Fill(ds, "news");
DataColumn code = new DataColumn();
code.AutoIncrement = true;
code.AutoIncrementSeed = 1;
code.AutoIncrementStep = 1;
ds.Tables["news"].Columns.Add(code);
DataRow [] dr= ds.Tables["news"].Select("id='"+idd+"'");
string i = dr[0][6].ToString();
为何得到的i的值为空?
原因在于
code.AutoIncrement = true;
code.AutoIncrementSeed = 1;
code.AutoIncrementStep = 1;
只对插入的新行有作用!
//DataTable myDt=new DataTable();
//DataColumn dc_index=new DataColumn("index",typeof(int));
//dc_index.AutoIncrement=true;
//dc_index.AutoIncrementSeed=1;
//dc_index.AutoIncrementStep=3;
// myDt.Columns.Add(dc_index);
//DataColumn dc=new DataColumn("dd",typeof(string));
//myDt.Columns.Add(dc);
//for(int i=0;i<10;i++)
//{
//DataRow mydr=myDt.NewRow();
//mydr[1]=i+"i";
//myDt.Rows.Add(mydr);
//}
//vardg.DataSource=myDt;
//vardg.DataBind();
sqlConnection1.Open();
sqlDataAdapter1.Fill(dataSet1);
DataTable dt=dataSet1.Tables[0];
DataColumn dc_index=new DataColumn("index",typeof(int));
dt.Columns.Add(dc_index);
for(int i=0;i<dt.Rows.Count;i++)
{
dt.Rows[i]["index"]=i+1;
}
vardg.DataSource=dt;
vardg.DataBind();