Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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# 更新数据集的特定列';将表数据转换为SQL数据库_C#_Asp.net_Vb.net - Fatal编程技术网

C# 更新数据集的特定列';将表数据转换为SQL数据库

C# 更新数据集的特定列';将表数据转换为SQL数据库,c#,asp.net,vb.net,C#,Asp.net,Vb.net,我有一个从我的数据库加载数据的gridview和一个gridview交换函数,在使用列调用“Priority”在行之间交换数据之后,我想将这些更改保存回我的数据库 只有“Priority”列的值将更改,如何仅将数据集表的该列更新到SQL数据库?请大家多多指教,谢谢 代码: Protected Sub Gridviewselectbus_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)

我有一个从我的数据库加载数据的gridview和一个gridview交换函数,在使用列调用“Priority”在行之间交换数据之后,我想将这些更改保存回我的数据库

只有“Priority”列的值将更改,如何仅将数据集表的该列更新到SQL数据库?请大家多多指教,谢谢

代码:

Protected Sub Gridviewselectbus_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)

        If e.CommandName = "Up" Then

            Dim index As Int16 = Convert.ToInt16(e.CommandArgument)
            If index = 0 Or index = 1 Then
                Exit Sub
            End If

            Dim objCampaignManagementTable As New CampaignManagementBLL
            Dim ds As DataSet = objCampaignManagementTable.SelectCampaignManagementTableListing()

            Dim dtr As DataRow = ds.Tables(0).Rows(index - 1)

            Dim dtrSwap As DataRow = ds.Tables(0).Rows(index - 2)
            Dim dc As DataColumn = ds.Tables(0).Columns(6)

            'Dim value As Int16 = Convert.ToInt16(dt.Rows(index)("Priority"))
            Dim value As Int16 = CType((dtr)(dc), Short)
            Dim temp1 As Int16 = value

            'Increases the selected row's priority
            dtr(dc) = value - 1

            'Decreases the priority of the row that is on top of the selected row by assigning 
            'the original selected row value to it.
            dtrSwap(dc) = value

            ds.Tables(0).DefaultView.Sort = "Priority"
            ds.Tables(0).AcceptChanges()
            dtNew = ds.Tables(0).Copy()
            uigvList.DataSource = ds.Tables(0)
            uigvList.DataBind()
            ds.Tables(0).AcceptChanges()

            For i As Integer = 0 To uigvList.Rows.Count - 1
                dtNew.Rows(i)("Code") = uigvList.Rows(i).Cells(1).Text
                dtNew.Rows(i)("Name") = uigvList.Rows(i).Cells(2).Text
                dtNew.Rows(i)("Type") = uigvList.Rows(i).Cells(3).Text
                dtNew.Rows(i)("ActiveDateFrom") = uigvList.Rows(i).Cells(4).Text
                dtNew.Rows(i)("ActiveDateTo") = uigvList.Rows(i).Cells(5).Text
                dtNew.Rows(i)("Priority") = uigvList.Rows(i).Cells(6).Text
            Next

          ' Update database
End if

  If e.CommandName = "down" Then

' Down code here

End Sub

看看这段代码,这只会更新特定列,然后还会更新sql server数据库

我希望这对你有帮助

注:catDA表示数据适配器…这是唯一的示例…如何更新

catDA.UpdateCommand = new OdbcCommand("UPDATE Categories SET CategoryName = ? " +
                                      "WHERE CategoryID = ?" , nwindConn);

catDA.UpdateCommand.Parameters.Add("@CategoryName", OdbcType.VarChar, 15, "CategoryName");

OdbcParameter workParm = catDA.UpdateCommand.Parameters.Add("@CategoryID", OdbcType.Int);
workParm.SourceColumn = "CategoryID";
workParm.SourceVersion = DataRowVersion.Original;

DataSet catDS = new DataSet();
catDA.Fill(catDS, "Categories");    

DataRow cRow = catDS.Tables["Categories"].Rows[0];

cRow["CategoryName"] = "New Category";

DataRow[] modRows = catDS.Tables["Categories"].Select(null, null, DataViewRowState.ModifiedCurrent);
catDA.Update(modRows);

出于好奇,为什么在这里?