static void UseDataTable(DbDataTable myDataTable, DbConnection myConnection) { myDataTable.Connection = myConnection; myDataTable.SelectCommand = myConnection.CreateCommand(); myDataTable.SelectCommand.CommandText = "SELECT e.EMPNO, e.ENAME, e.JOB, d.DNAME FROM Dept d, Emp e where d.Deptno = e.Deptno"; myDataTable.FetchAll = true; myDataTable.CachedUpdates = false; myDataTable.UpdatingTable = "Emp"; myDataTable.UpdatingKeyFields = "EMPNO"; myDataTable.UpdatingFields = "EMPNO;ENAME;JOB"; myDataTable.Open(); DataRow row = myDataTable.Rows[0]; row[myDataTable.Columns["ENAME"]] = "John Smith"; myDataTable.Update(); myDataTable.Close(); }
Private Shared Sub UseDataTable(ByVal myDataTable As DbDataTable, ByVal myConnection As DbConnection) myDataTable.Connection = myConnection myDataTable.SelectCommand = myConnection.CreateCommand myDataTable.SelectCommand.CommandText = "SELECT e.EMPNO, e.ENAME, e.JOB, d.DNAME" + _ "FROM Dept d, Emp e " + _ "where d.Deptno = e.Deptno" myDataTable.FetchAll = True myDataTable.CachedUpdates = False myDataTable.UpdatingTable = "Emp" myDataTable.UpdatingKeyFields = "EMPNO" myDataTable.UpdatingFields = "EMPNO;ENAME;JOB" myDataTable.Open() Dim row1 As DataRow = myDataTable.Rows.Item(0) row1.Item(myDataTable.Columns.Item("ENAME")) = "John Smith" myDataTable.Update() myDataTable.Close() End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2