C#如何把数据集(dateset)查询生成的表中的某个列的值取出来

2025-01-20 01:12:29
推荐回答(2个)
回答1:

C#中将数据集(dateset)查询生成的表中的某个列的值取出来(这里将查询到的SUM值取出)

            实现销售额统计
            SqlConnection MyConnection = new SqlConnection();
            MyConnection.ConnectionString = global::MySale.Properties.Settings.Default.MySaleConnectionString;
            MyConnection.Open();
            string MySQL = "SELECT SUM(dbo.销售出库明细视图.金额) AS MONEY FROM 销售出库明细视图 WHERE 出库日期 BETWEEN '" + this.销售开始日期DateTimePicker.Value.ToString() + "' AND '" + this.销售结束日期DateTimePicker.Value.ToString() + "' AND 商品名称 LIKE '" + this.商品名称ComboBox.Text + "'";
            SqlDataAdapter MyAdapter =new SqlDataAdapter(MySQL,MyConnection);

            DataSet dataset = new DataSet();
            dataset.Tables.Add("money");
            MyAdapter.Fill(dataset, "money");
            销售额统计textBo.Text = dataset.Tables["money"].Rows[0]["MONEY"].ToString();

回答2:

dataset.Tables["PersonInfo"].Rows[0]["age"].ToString();