是因为你声明了两个相同的变量你把变量改成不一样就行了
private string sendStrSQL = "select 进货单明细历史.货号,拼音编码,品名,单位,仓库 " +
  "from 进货单明细历史,商品清单 where 进货单明细历史.货号 = 商品清单.货号";  private string sendStrSQL1 = "select 库存库.库存数量,库存单价,库存金额 " +
  "from 库存库,进货单明细历史 where 库存库.库存数量 = 进货单明细历史.进货数量 and 库存库.库存单价 = 进货单明细历史.进价 and 库存库.库存金额 = 进货单明细历史.税价合计";

解决方案 »

  1.   

    以上语句发生矛盾,不可以声明两次sendStrSQL。可是,需要既调用进货单明细历史表,又要调用库存库表里的数据,应该怎写才对?你分2次分别调用不就完了嘛
      

  2.   

    sendStrSQL变量名改成不同的,分两次去执行sql
      

  3.   

      代码改成:private string sendStrSQL = "select 进货单明细历史.货号,拼音编码,品名,单位,仓库 " +
      "from 进货单明细历史,商品清单 where 进货单明细历史.货号 = 商品清单.货号";
      private string sendStrSQL1 = "select 库存库.库存数量,库存单价,库存金额 " +
      "from 库存库,进货单明细历史 where 库存库.库存数量 = 进货单明细历史.进货数量 and 库存库.库存单价 = 进货单明细历史.进价 and 库存库.库存金额 = 进货单明细历史.税价合计";程序可以运行了。
       可是库存界面显示不出sendStrSQL1 的数据。????将this.ds = this.link.SelectDataBase(sendStrSQL ,sendTableName);改成this.ds = this.link.SelectDataBase(sendStrSQL ,sendStrSQL1,sendTableName);还出错,怎么回事啊?
      

  4.   

    this.ds是什么 SelectDataBase又是什么函数?你问的还真深奥你这是打算一个控件同时显示2个结果集?
      

  5.   

    private string sendStrSQL = "select 进货单明细历史.货号,拼音编码,品名,单位,仓库 " +
      "from 进货单明细历史,商品清单 where 进货单明细历史.货号 = 商品清单.货号" +
      "select 库存库.库存数量,库存单价,库存金额 " +
      "from 库存库,进货单明细历史 where 库存库.库存数量 = 进货单明细历史.进货数量 and 库存库.库存单价 = 进货单明细历史.进价 and 库存库.库存金额 = 进货单明细历史.税价合计";
      

  6.   

    蛋疼的提问者问晕蛋疼的回答者。局部定义了两个一样的变量说明你的基础还很不牢靠。
    如果你是要两个结果集分别处理,那就执行两次select from...
    如果你是要两表关联抽一个结果集,那就是一次select语句中用inner join、 left join之类的。
      

  7.   

    REATE TABLE [dbo].[库存库] (
    [货号] [char] (14) NOT NULL ,
    [仓库] [varchar] (20) NOT NULL ,
    [库存数量] [decimal] (28,6) NOT NULL ,
    [库存金额] [decimal] (28,6) NOT NULL ,
    [库存单价] [decimal] (28,6) NOT NULL ,
    [最新进价] [decimal] (28,6) NULL 
    )
    GO
    CREATE TABLE [dbo].[进货单] (
    [编号] [char] (14) Not NULL Primary key,
    [供货商号] [char] (10) NOT NULL ,
    [进货日期] [datetime] NULL,
    [业务员]   [char] (10) NULL ,
    [制单人]   [char] (10) NULL ,
    [验收员] [char] (10) NULL ,
    [保管员] [char] (10) NULL ,
    [税价合计] [decimal] (28,6) NULL ,
    [不含税价] [decimal] (28,6) NULL ,
    [税额] [decimal] (28,6) NULL, 
    [订单号] [char] (14) NULL
    )
    GOCREATE TABLE [dbo].[进货单明细] (
    [编号] [char] (14) Not NULL Primary key,
    [进货单号] [char] (14) Not NULL ,
    [货号] [char] (14) NOT NULL ,
    [进货数量] [decimal] (28,6) NOT NULL ,
    [进价] [decimal] (28,6) NULL ,
    [税价合计] [decimal] (28,6) NULL ,
    [扣率] [decimal] (28,6) NULL ,
    [税率] [decimal] (28,6) NULL ,
    [不含税价] [decimal] (28,6) NULL ,
    [税额] [decimal] (28,6) NULL ,
    [仓库] [char] (20) NULL ,
    [货物质量] [varchar] (50) NULL 
    )
    GOCREATE TABLE [dbo].[进货单历史] (
    [编号] [char] (14) Not NULL Primary key,
    [供货商号] [char] (10) NOT NULL ,
    [进货日期] [datetime] NULL,
    [业务员]   [char] (10) NULL ,
    [制单人]   [char] (10) NULL ,
    [验收员] [char] (10) NULL ,
    [保管员] [char] (10) NULL ,
    [税价合计] [decimal] (28,6) NULL ,
    [不含税价] [decimal] (28,6) NULL ,
    [税额] [decimal] (28,6) NULL , 
    [订单号] [char] (14) NULL
    )
    GOCREATE TABLE [dbo].[进货单明细历史] (
    [编号] [char] (14) Not NULL Primary key,
    [进货单号] [char] (14) Not NULL ,
    [货号] [char] (14) NOT NULL ,
    [进货数量] [decimal] (28,6) NOT NULL ,
    [进价] [decimal] (28,6) NULL ,
    [税价合计] [decimal] (28,6) NULL ,
    [扣率] [decimal] (28,6) NULL ,
    [税率] [decimal] (28,6) NULL ,
    [不含税价] [decimal] (28,6) NULL ,
    [税额] [decimal] (28,6) NULL ,
    [仓库] [char] (20) NULL ,
    [货物质量] [varchar] (50) NULL 
    )
    GO
      

  8.   

    库存表的主要代码:namespace 进销存管理系统
    {
    /// <summary>
    /// StorageSearch 的摘要说明。
    /// </summary>
    public class StorageSearch : System.Windows.Forms.Form
    {
    private DataSet ds = new DataSet();
    private DataView dv;
    private LinkDataBase link = new LinkDataBase();
    private string sendTableName = "库存商品";
            private string sendStrSQL = "select 进货单明细历史.货号,拼音编码,品名,单位,仓库 " +
            "from 进货单明细历史,商品清单 where 进货单明细历史.货号 = 商品清单.货号"+
            "select 库存库.库存数量,库存单价,库存金额 " +
            "from 库存库,进货单明细历史 where 库存库.库存数量 = 进货单明细历史.进货数量 and 库存库.库存单价 = 进货单明细历史.进价 and 库存库.库存金额 = 进货单明细历史.税价合计";
    //---------------将查询得到的仓库信息添加到下拉列表框中---------------
    private void selectDataBase()
    {
                this.ds = this.link.SelectDataBase(sendStrSQL ,sendTableName);
    this.dv = new DataView(ds.Tables[0]);
    this.dgrd_StorageSearch.DataSource = dv;
    this.cmb_Storage.Items.Add(""); //首先加入一个空白,以用作查询全部仓库的库存货物
    //从库存库中读取所有仓库并排斥性的加入保存仓库号的组合框中
    for (int i=0;i<ds.Tables[0].Rows.Count;i++)//外循环是判断库存库中的有多少行
    {
    for (int j=0;j<this.cmb_Storage.Items.Count;j++)//内循环是判断当前要加进去的仓库号在组合框中是否已存在
    {
    if (ds.Tables[0].Rows[i][4].ToString().Trim() == this.cmb_Storage.Items[j].ToString())
    {
    goto END;//如果组合框中已存在当前要加入的仓库号,则转到END标识处,组合框中不加入该仓库号
    }
    }
    //如果组合框中尚不存在该仓库号,则将它加进去
    this.cmb_Storage.Items.Add(ds.Tables[0].Rows[i][4].ToString().Trim());
    END:{};
    }
    this.cmb_Storage.SelectedIndex = 0;
    } //--------------根据输入查询库存中商品信息--------------
    private void btn_Search_Click(object sender, System.EventArgs e)
    {
    string strRowFilter = "";
    string strWareNumFilter ="货号 like '" + txt_WareNum.Text.Trim() + "%'";
    string strWareWordFilter ="拼音编码 like '" + txt_WareWord.Text.Trim() + "%'";
    int selectedNum = cmb_Storage.SelectedIndex;
    string strStorageFilter ="仓库 = '" + cmb_Storage.Items[selectedNum].ToString().Trim()+ "'";

    if (txt_WareNum.Text.Trim() != "")
    strRowFilter += strWareNumFilter + " and ";
    if (txt_WareWord.Text.Trim() != "")
    strRowFilter += strWareWordFilter + " and ";
    if (cmb_Storage.Items[selectedNum].ToString().Trim() != "")
    strRowFilter += strStorageFilter + " and "; if (strRowFilter != "")  // 存在查询条件
    strRowFilter = strRowFilter.Substring(0,strRowFilter.Length-5);
    dv.RowFilter = strRowFilter;
    } //-----------设置表格状态--------------
    private void DataGridStateControl()
    {
    DataGridTableStyle ts = new DataGridTableStyle();
    DataGridNoActiveCellColumn aColumnTextColumn;
    ts.AlternatingBackColor = Color.LightGray;
    ts.MappingName = this.ds.Tables[0].TableName;
    int numCols = this.ds.Tables[0].Columns.Count;
    for (int i = 0;i< numCols;i++)
    {
    aColumnTextColumn = new DataGridNoActiveCellColumn();
    aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
    aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
    aColumnTextColumn.NullText = "";
    aColumnTextColumn.Format = "D";
    ts.GridColumnStyles.Add(aColumnTextColumn);
    }
    this.dgrd_StorageSearch.TableStyles.Add(ts);
    }        private void StorageSearch_Load(object sender, EventArgs e)
            {        }
    }
    }
      

  9.   

    //---------提交修改--------
    private void clickedSaveIcon()
    {
    try
    {
    //注意:必须先删除进货单明细表中的数据,然后才能再删除进货单中的数据
    string sendSQL = "delete 进货单明细";
    this.link.UpdateDataBase(sendSQL); //删除进货单明细中的数据
    sendSQL = "delete 进货单";
    this.link.UpdateDataBase(sendSQL); //删除进货单中的数据
    //向进货单中写入数据
    int intMaxStockNumberID= 0;
    sendSQL = "select 编号 from 进货单历史";
    //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
    DataTable intNumberTable = this.link.SelectDataBase(sendSQL);
    for (int i=0;i<intNumberTable.Rows.Count;i++)
    {
    if (intMaxStockNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
    {
    intMaxStockNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
    }
    }
    sendSQL = "select 编号 from 进货单";
    //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
    intNumberTable = this.link.SelectDataBase(sendSQL);
    for (int i=0;i<intNumberTable.Rows.Count;i++)
    {
    if (intMaxStockNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
    {
    intMaxStockNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
    }
    }
    intMaxStockNumberID++;
    string strStokerID =this.cmb_StokerID.Items[0].ToString().Trim();
    string strStockDate =this.txt_StockDate.Text.Trim();
    string strOperator =this.cmb_Oprater.SelectedItem.ToString().Trim();
    string strMaker =this.txt_Maker.Text.Trim();
    decimal decTotalCount = Decimal.Parse(this.txt_TotalCount.Text.Trim());
    decimal decNoTax = Decimal.Parse(this.txt_NoTax.Text.Trim());
    decimal decTax = Decimal.Parse(this.txt_Tax.Text.Trim());
    string sendValues = "('" + intMaxStockNumberID +"','"+ strStokerID +"','"+ strStockDate +"','"+ strOperator +"','"+
    strMaker +"','"+ decTotalCount +"','"+ decNoTax +"','"+ decTax + "')";
    sendSQL = "insert 进货单 (编号,供货商号,进货日期,业务员,制单人,税价合计,不含税价,税额) values " + sendValues;
    this.link.UpdateDataBase(sendSQL);//向进货单明细中写入数据
    int intMaxNumberID = 0;  
    sendSQL = "select 编号 from 进货单明细历史";
    //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
    intNumberTable = this.link.SelectDataBase(sendSQL);
    for (int i=0;i<intNumberTable.Rows.Count;i++)
    {
    if (intMaxNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
    {
    intMaxNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
    }
    }
    sendSQL = "select 编号 from 进货单明细";
    //从进货单明细中读取"编号"列,取它的最大值,以便为新添加的数据编号
    intNumberTable = this.link.SelectDataBase(sendSQL);
    for (int i=0;i<intNumberTable.Rows.Count;i++)
    {
    if (intMaxNumberID < System.Int32.Parse(intNumberTable.Rows[i][0].ToString()))
    {
    intMaxNumberID = System.Int32.Parse(intNumberTable.Rows[i][0].ToString());
    }
    }
    for (int row=0;row<this.newTable.Rows.Count;row++)
    {
    //首先判断表中的下一行数据是否为空,如果是则返回,以免因向数据库中写入空行而出错
    if(this.newTable.Rows[row][0].ToString() == "")
    {
    sendSQL = "delete from 进货单 where 编号 = '" + intMaxStockNumberID + "'";
    this.link.UpdateDataBase(sendSQL); //首先删除这次在进货单中加入的数据
    break;
    }
    else
    {
    intMaxNumberID++;
    string strWareID = this.dgrd_StockTable[row,0].ToString().Trim();
    string strWareCount = this.dgrd_StockTable[row,1].ToString().Trim();
    string strWarePrice = this.dgrd_StockTable[row,2].ToString().Trim();
    string strStorageID = this.dgrd_StockTable[row,3].ToString().Trim();
    decTotalCount = Decimal.Parse(this.dgrd_StockTable[row,6].ToString().Trim());
    decTax = Decimal.Parse(this.dgrd_StockTable[row,8].ToString().Trim());
    decNoTax = Decimal.Parse(this.dgrd_StockTable[row,9].ToString().Trim());
    sendValues = "('" + intMaxNumberID +"','"+intMaxStockNumberID +"','"+ strWareID +"','"+ strWareCount +"','"+ strWarePrice +"','"+
    decTotalCount +"','"+ 17 +"','"+ decNoTax +"','"+ decTax +"','"+ strStorageID + "')";
    sendSQL = "insert 进货单明细 (编号,进货单号,货号,进货数量,进价,税价合计,税率,不含税价,税额,仓库) values " + sendValues;
    this.link.UpdateDataBase(sendSQL);  
    }
    }
    MessageBox.Show("数据保存成功!","信息");
    }
    catch
    {
    MessageBox.Show("数据保存失败,请确认所有信息输入完整且正确!","提示");
    return;
    }
    }//----------打印报表----------
    private void clickedPrintIcon()
    {
    CrystalReport newCrystalReport_Stock = new CrystalReport();
    newCrystalReport_Stock.ShowDialog();
    Trash();
    }//----------保存历史记录并清除原数据----------
    private void Trash()
    {
    try
    {
    if (MessageBox.Show("要保存为历史记录吗?","询问",MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
    this.link.UpdateDataBase("exec sf_进货单"); //调用存储过程
    //清除供货商信息
    this.cmb_StokerID.Items[0] = "";
    this.txt_StokerName.Text = "";
    //清除底部金额及税款信息
    this.txt_TotalCount.Text = "0.00";
    this.txt_NoTax.Text = "0.00";
    this.txt_Tax.Text = "0.00";
    //清除当前DataGrid中的所有数据
    newTable.Clear();
    //加入空行保证newTable中不为空,否则删除所有数据行后保存数据和MouseUp函数将引发异常出错
    newTable.Rows.Add(newTable.NewRow());
    MessageBox.Show("数据成功存入历史表!","信息");
    }
    }
    catch
    {
    MessageBox.Show("数据存入历史表时出错,请检查数据库!","提示");
    }
    }//-------------将所选择的货物信息填入表格中---------------
    private void selectWareMessage()
    {
    int intCurrentRowNumber = this.dgrd_StockTable.CurrentCell.RowNumber;
    //判断何时需要检索数据库的商品清单,读取商品信息(以免操作数据库次数过多,影响程序性能)
    if (this.dgrd_StockTable[intCurrentRowNumber,0].ToString() != "")
    {
    string strSearchWord = this.dgrd_StockTable[intCurrentRowNumber,0].ToString().Trim();
    string sendSQL = "select 货号,品名,单位 from 商品清单 where 货号 = '" + strSearchWord + "'";
    DataTable tempDataTable = this.link.SelectDataBase(sendSQL);
    if (tempDataTable.Rows.Count>0)
    {
    inputDataGridArray[0] = tempDataTable.Rows[0][0].ToString().Trim();
    inputDataGridArray[1] = tempDataTable.Rows[0][1].ToString().Trim();
    inputDataGridArray[2] = tempDataTable.Rows[0][2].ToString().Trim();
    this.setWareData();
    }
    //如果从数据库中没有检索出任何数据
    else
    {
    //inputDataGridArray[0]赋值为当前输入的值,方便用户再次修改输入
    inputDataGridArray[0] = this.dgrd_StockTable[intCurrentRowNumber,0].ToString().Trim();
    inputDataGridArray[1] = "";
    inputDataGridArray[2] = "";
    this.setWareData();
    }
    }
    }
    现已将进货单、库存表的主要代码和对应的数据库信息列出,应该如何改能实现进货单保存的数据在库存中正确的显示?
      

  10.   

    select语句中用inner join、 left join链接多表。
      

  11.   


    http://download.csdn.net/detail/abcabc117/4270684:完整程序,谁能帮我解决以下问题:
    1)进货单保存的数据在库存中无法显示。2)销售单保存数据后,查看库存数量没有改变。
      

  12.   

    http://download.csdn.net/detail/abcabc117/4270684:完整程序,谁能帮我解决以下问题:
    1)进货单保存的数据在库存中无法显示。2)销售单保存数据后,查看库存数量没有改变。
      

  13.   


    select 进货单明细历史.货号,拼音编码,品名,单位,仓库,商品清单.货号,库存库.库存数量,库存单价,库存金额 from 进货单明细历史 inner join 商品清单 on 进货单明细历史.货号 = 商品清单.货号 inner join 库存库 on 库存库.库存数量 = 进货单明细历史.进货数量 and 库存库.库存单价 = 进货单明细历史.进价 and 库存库.库存金额 = 进货单明细历史.税价合计";这句话有什么问题?
      

  14.   


    --你的代码,基本上不可能得到数据,从表面看没啥子关联关系。
    select 进货单明细历史.货号,拼音编码,品名,单位,仓库,商品清单.货号,库存库.库存数量,库存单价,库存金额 from 进货单明细历史 inner join 商品清单 on 进货单明细历史.货号 = 商品清单.货号 inner join 库存库 on 库存库.货号 = 进货单明细历史.货号