Skip to content

Dataset

garbage

Asked Jun 28, 2006, 3:29 AM EDT1 answer
Share
LinkedInX

i have these very long lines of code. which i think can be shorten.

it has a master data that which came from dataset "ds".
from the set of data in ds. it willl get another data that which give the master data its details.

how can i make this lines of code shorter.?.
[CODE]

C#
dsDetails = altStock.fetchStockDetails(ds.Tables[0].Rows[rowIndex]["customerCode"].ToString());
            decimal wareQty = dsDetails.Tables[0].Rows[0]["custQty"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custQty"]);
            decimal prodQty = dsDetails.Tables[0].Rows[0]["custName"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custName"]);
            decimal finQty = wareQty + prodQty;
            this.txtDesc.Text = dsDetails.Tables[0].Rows[0]["custAddress"].ToString();
            this.txtQty.Text = finQty.ToString();
            this.txtSpecs.Text = dsDetails.Tables[0].Rows[0]["custAddress1"].ToString();

            dsDetails = altStock.fetchStockDetails(ds.Tables[0].Rows[rowIndex]["customerCode1"].ToString());
            wareQty = dsDetails.Tables[0].Rows[0]["custQty"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custQty"]);
            prodQty = dsDetails.Tables[0].Rows[0]["custName"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custName"]);
            finQty = wareQty + prodQty;
            this.txtDesc1.Text = dsDetails.Tables[0].Rows[0]["custAddress"].ToString();
            this.txtQty1.Text = finQty.ToString();
            this.txtSpecs1.Text = dsDetails.Tables[0].Rows[0]["custAddress1"].ToString();
            dsDetails = altStock.fetchStockDetails(ds.Tables[0].Rows[rowIndex]["customerCode2"].ToString());
            wareQty = dsDetails.Tables[0].Rows[0]["custQty"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custQty"]);
            prodQty = dsDetails.Tables[0].Rows[0]["custName"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custName"]);
            finQty = wareQty + prodQty;
            this.txtDesc2.Text = dsDetails.Tables[0].Rows[0]["custAddress"].ToString();
            this.txtQty2.Text = finQty.ToString();
            this.txtSpecs2.Text = dsDetails.Tables[0].Rows[0]["custAddress1"].ToString();
            dsDetails = altStock.fetchStockDetails(ds.Tables[0].Rows[rowIndex]["Amt_AltStockcode3"].ToString());
            wareQty = dsDetails.Tables[0].Rows[0]["custQty"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custQty"]);
            prodQty = dsDetails.Tables[0].Rows[0]["custName"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custName"]);
            finQty = wareQty + prodQty;
            this.txtDesc4.Text = dsDetails.Tables[0].Rows[0]["custAddress"].ToString();
            this.txtQty3.Text = finQty.ToString();
            this.txtSpecs3.Text = dsDetails.Tables[0].Rows[0]["custAddress1"].ToString();
            dsDetails = altStock.fetchStockDetails(ds.Tables[0].Rows[rowIndex]["customerCode4"].ToString());
            wareQty = dsDetails.Tables[0].Rows[0]["custQty"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custQty"]);
            prodQty = dsDetails.Tables[0].Rows[0]["custName"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custName"]);
            finQty = wareQty + prodQty;
            this.txtStockDesc.Text = dsDetails.Tables[0].Rows[0]["custAddress"].ToString();
            this.txtQty4.Text = finQty.ToString();
            this.txtSpecs4.Text = dsDetails.Tables[0].Rows[0]["custAddress1"].ToString();
            dsDetails = altStock.fetchStockDetails(ds.Tables[0].Rows[rowIndex]["customerCode5"].ToString());
            wareQty = dsDetails.Tables[0].Rows[0]["custQty"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custQty"]);
            prodQty = dsDetails.Tables[0].Rows[0]["custName"] == null ? 0 : Convert.ToDecimal(dsDetails.Tables[0].Rows[0]["custName"]);
            finQty = wareQty + prodQty;
            this.txtDesc5.Text = dsDetails.Tables[0].Rows[0]["custAddress"].ToString();
            this.txtQty5.Text = finQty.ToString();
            this.txtSpecs5.Text = dsDetails.Tables[0].Rows[0]["custAddress1"].ToString();[/CODE]

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    If your data structure is static, then use a typed dataset and from there you can just access the data directly by iterating thru the rows collection of a named table.
    0