在asp.net中,怎样把从数据库查询出的一行数据分别取出它每一列的值?

SqlConnection con = new SqlConnection(@“server=.\sqlexpress;database=TestDataBase;uid=sa;pwd=123”);
con.Open();
SqlCommand cmd = new SqlCommand(“select * from Test1”, con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
比如你的sql语句是这样的
ds.Table[0]就是你查询到的表数据
ds.Table[0].Rows[0]就是第一行
ds.Table[0].Rows[0][0]就是第一行第一列的值
ds.Table[0].Rows[1][2]就是第二行第三列的值

猜你喜欢

转载自blog.csdn.net/qq_41661800/article/details/106048292