public List<dFiledTree> d_BZWH_dis_BZFiled_ByType_ByTreeAs2(string ObjectType, string UserName, int TypeAID) { List<dFiledTree> list = new List<dFiledTree>(); SqlConnection userConnection = SQLHelper.getConn(); SqlCommand userCommand = new SqlCommand("d_BZWH_dis_BZFiled_ByType_ByTree2", userConnection); userCommand.CommandType = CommandType.StoredProcedure;//采用存储过程 userCommand.Parameters.Add("@ObjectType", SqlDbType.VarChar, 50);//存储过程参数 userCommand.Parameters.Add("@UserName", SqlDbType.VarChar, 50);//存储过程参数 userCommand.Parameters.Add("@TypeAID", SqlDbType.Int);//存储过程参数 userCommand.Parameters["@ObjectType"].Value = ObjectType;//给参数赋值 userCommand.Parameters["@UserName"].Value = UserName;//给参数赋值 userCommand.Parameters["@TypeAID"].Value = TypeAID;//给参数赋值 userCommand.Connection.Open(); SqlDataAdapter adapter = new SqlDataAdapter(userCommand); DataSet ds = new DataSet(); adapter.Fill(ds, "table1"); Console.WriteLine(ds.Tables["table1"].Rows[0][0]); for (int i = 0; i < ds.Tables["table1"].Rows.Count; i++) { Console.WriteLine(ds.Tables["table1"].Rows[i][1]); dFiledTree item = new dFiledTree(); item.Id = ds.Tables["table1"].Rows[i]["Id"].ToString(); item.ParentId = ds.Tables["table1"].Rows[i]["ParentId"].ToString(); item.MainAID = ds.Tables["table1"].Rows[i]["MainAID"].ToString(); item.Text = ds.Tables["table1"].Rows[i]["Text"].ToString(); item.Text1= ds.Tables["table1"].Rows[i]["Text1"].ToString(); item.Text2= ds.Tables["table1"].Rows[i]["Text2"].ToString(); item.Text3= ds.Tables["table1"].Rows[i]["Text3"].ToString(); Console.WriteLine(ds.Tables["table1"].Rows[i]["Id"]); Console.WriteLine(ds.Tables["table1"].Rows[i]["ParentId"]); list.Add(item); } return list; }
从数据集的表中取数据,有两种方式.
1: 使用数字索引
如:
ds.Tables["table1"].Rows[0][0]
2:使用列名
如:
ds.Tables["table1"].Rows[0]["Id"] 取得第一行中 列为id的值标签:Tables,table1,数据库,userCommand,item,Rows,ADO,net,ds From: https://www.cnblogs.com/aashui/p/16649172.html