Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 匹配另一个表中的多行时更新多行_C#_.net_Ado.net - Fatal编程技术网

C# 匹配另一个表中的多行时更新多行

C# 匹配另一个表中的多行时更新多行,c#,.net,ado.net,C#,.net,Ado.net,我有一个存储表,其中有更多的行,列名为Quantity,我还有一个tempStore表,我向这个tempStore表插入数据,它还有一个列名为Quantity,当我将所有数据输入tempStore时,我有一个Send按钮将数据发送到存储表,只更新Quantity列,例如,在Store table Quantity=20(针对一行)和tempStore Quantity=10(针对一行)中,当我按下send(发送)按钮时,我可以轻松地更新此行,Store table中的Quantity(数量)列将

我有一个存储表,其中有更多的行,列名为Quantity,我还有一个tempStore表,我向这个tempStore表插入数据,它还有一个列名为Quantity,当我将所有数据输入tempStore时,我有一个Send按钮将数据发送到存储表,只更新Quantity列,例如,在Store table Quantity=20(针对一行)和tempStore Quantity=10(针对一行)中,当我按下send(发送)按钮时,我可以轻松地更新此行,Store table中的Quantity(数量)列将为30,但为什么我不能更新所有匹配的行?它只对一行执行此操作。 这是我的代码:

SqlConnection con = null;
con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=SuperMarketDB;Integrated Security=True; MultipleActiveResultSets=True");
con.Open();

SqlCommand cmd = new SqlCommand("SELECT * FROM [Store]", con);
SqlDataReader dr = null;
dr = cmd.ExecuteReader();

int inID = 0;
Int64 itemNo = 0;
int iQuantity = 0;

while (dr.Read())
{
    inID = int.Parse(dr[0].ToString());
    itemNo = Int64.Parse(dr[1].ToString());
    iQuantity = int.Parse(dr[4].ToString());

    for (int i = 0; i <= tempStoreDataGridView.Rows.Count-1; i++)
    {
        if (tempStoreDataGridView.Rows[i].Cells[1].Value != null)
        {
            Int64 barcode = Int64.Parse(tempStoreDataGridView.Rows[i].Cells[1].Value.ToString());
            if (barcode == itemNo)
            {                   
                iQuantity = iQuantity + int.Parse(quantityTextBox.Text.ToString());
                inItemsTableAdapter1.UpdateQuery(iQuantity, itemNo, inID);
                tempStoreTableAdapter.DeleteQuery();
                tempStoreTableAdapter.Fill(this.tempStoreDataSet.TempStore);
                lblWarning.Visible = true;
            }
        }
    }
}
SqlConnection con=null;
con=new-SqlConnection(@“数据源=。\SQLEXPRESS;初始目录=SuperMarketDB;集成安全性=True;MultipleActiveResultSets=True”);
con.Open();
SqlCommand cmd=newsqlcommand(“从[Store]中选择*”,con);
SqlDataReader dr=null;
dr=cmd.ExecuteReader();
int-inID=0;
Int64 itemNo=0;
int IQUANTY=0;
while(dr.Read())
{
inID=int.Parse(dr[0].ToString());
itemNo=Int64.Parse(dr[1].ToString());
iQuantity=int.Parse(dr[4].ToString());

对于(int i=0;i)执行多余的操作:首先将目标类型中的数据转换为字符串,然后返回到目标类型。使用和类似。您的注释不清楚,请澄清。而不是
int i=int.Parse(dr[0].ToString());
使用
int i=dr.GetInt32(0)
,那就更有效了。好吧,我做了,但这不是我的问题,读我的问题。我知道,这只是一个离题和背景建议,这就是为什么它是一个评论,而不是答案。