473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Need an example of updating an item within a SQL Table

21
Hi,
I am looking for an example of how to update a SQL table after you have done the SELECT query and using IDataReader or SQLAdapter. I think the format is something like Table.row.update(0) (5) to update the 1st row, the sixth data element. I want to update just the sixth element, not the whole row.

Does anyone have a code example of this?

Pleaes Help.

Thanks,
Mar 11 '07 #1
2 1088
willakawill
1,646 1GB
Please post the code you have so far and we will take it from there
Mar 11 '07 #2
JimN1
21
Please post the code you have so far and we will take it from there
Below is the test I have been working on. The section P010_Claim_Loop:
is the part I am having trouble with.

Imports System
Imports System.Reflection
Imports System.Text
Imports System.Collections
Imports System.Globalization
Imports System.Data.SqlClient
Imports System.Data
Imports System.IO

Module Module1
'Global Defs
Dim EDIConn As SqlConnection
Dim AAConn As SqlConnection
Dim SQLCmd As SqlCommand
Dim SQLAdapter As SqlDataAdapter
Dim trans As SqlTransaction
Dim DSet As DataSet
Dim DTable As DataTable
Dim SQLQuery As String = ""
Dim RecsAffected As Integer = 0
Dim connstring As String
Dim MyTimeout As String



Sub Main()

P010_Claim_Type_Selection()
MsgBox("..What Does It Look Like? ..")

End Sub
Function P010_Claim_Type_Selection() As Boolean

Dim h As Integer = 0
Dim i As Integer = 0
Dim drow As DataRow

P010_Select_Claims:
SQLQuery = "SELECT * " + vbCrLf + _
" FROM Remit.Remit_Temp_Serv " + vbCrLf + _
" WHERE Rmt_Svc_Clm_Num = '061009B02097' " + vbCrLf + _
" ORDER BY Rec_Seq"
'trans = EDIConn.BeginTransaction()
'SQLCmd = New SqlCommand()
'SQLCmd.Connection = EDIConn
'SQLCmd.Transaction = trans
'SQLCmd.CommandText = SQLQuery
'SQLCmd.CommandTimeout = 30
'SQLCmd.CommandType = CommandType.Text
'RecsAffected = SQLCmd.ExecuteNonQuery()
'trans.Commit()
'SQLCmd = Nothing
'trans = Nothing

If P920_LoadEDITable() Then
DTable = DSet.Tables(0)
P010_Claim_Loop:
For Each drow In DTable.Rows
If DTable.Rows(i)(63).ToString() = "-" Then
If h > 0 Then
h = i - 1
Else
h = 0
End If
Try
AddHandler SQLAdapter.RowUpdating, AddressOf OnRowUpdating
AddHandler SQLAdapter.RowUpdated, AddressOf OnRowUpdated

DTable.Rows(h)(12) = DTable.Rows(i)(12).ToString() ' -- Tot_Paid_Amt
DTable.Rows(h)(59) = DTable.Rows(i)(59).ToString() ' -- ClmChk_CPT
DTable.Rows(h)(61) = DTable.Rows(i)(61).ToString() ' -- ClmChk_Bun
' Will the following update the SQL table or does it need a command to execute?
SQLAdapter.Update(DTable)
Catch ex As SqlException
Console.WriteLine("... Error UPDATING Temp Table: " & ex.Message & "...")
Console.WriteLine(".." & ex.Message & "..")
Console.WriteLine("... Error UPDATING Temp Table: " & ex.Message & "...")
End Try
i = i + 1
h = h + 1
End If
Next
End If

P010_Return:
Return P010_Claim_Type_Selection
End Function


Function P920_LoadEDITable() As Boolean

P920_LoadEDITable = True

SQLCmd = New SqlCommand()
SQLCmd.Connection = EDIConn
SQLCmd.CommandText = SQLQuery
SQLCmd.CommandType = CommandType.Text

SQLAdapter = New SqlDataAdapter()
SQLAdapter.SelectCommand = SQLCmd

DSet = New DataSet()
SQLAdapter.Fill(DSet)
Return P920_LoadEDITable()
End Function
' Handler for OnRowUpdating
Sub OnRowUpdating(ByVal sender As Object, ByVal e As SqlRowUpdatingEventArgs)
Console.WriteLine("OnRowUpdating Event")
If Not e.Status = UpdateStatus.Continue Then
Console.WriteLine("RowStatus = " & e.Status.ToString())
End If
End Sub

' Handler for OnRowUpdated
Sub OnRowUpdated(ByVal sender As Object, ByVal e As SqlRowUpdatedEventArgs)
Console.WriteLine("OnRowUpdated Event")
Console.WriteLine("Records Affected = " & e.RecordsAffected.ToString())
End Sub



End Module
Mar 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: | last post by:
Hello, Sorry to ask what is probably a simple answer, but I am having problems updating a table/database from a PHP/ PHTML file. I can Read From the Table, I can Insert into Table/Database, But...
13
by: EmbersFire | last post by:
I'm using a stored proceedure which should update a number of rows in a table depending on a key value supplied (in this case 'JobID'). But what's happening is when I call the proc from within the...
3
by: Jon Agiato | last post by:
Hi, I am trying to use a data grid in a web application in which I have three tiers. The DataGrid is not set up to a data source, or a data adapter, so everytime I make a change I send the cell...
0
by: cwbp17 | last post by:
I'm having trouble updating individual datagrid cells. Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables...
4
by: Gary Paris | last post by:
This should be simple but I can't get it to work. I want to update a single row of data in a table. ES.Clear() Dim strSQL As String = "Select * from Contact where sysid = '" & g_sysID & "'"...
2
by: toddw607 | last post by:
Hi Everyone! I have a ASP.NET webform that brings data in from SQL Server 2000 and displays it on a page. I want to update the webpage while in IE using the following code: <%@ Import...
3
by: Trez | last post by:
Hey guys, Am new at using ASP.Net. am having some problems updating my SQL DB. whenever i try i get this Error. Can someone help me? Incorrect syntax near 'nvarchar'. Description: An unhandled...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
0
by: preeti13 | last post by:
i have a two tables employeenominations and reason if someone storing a data first time it will store into the employeenominations table if name is already exist it will store into the reason table...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.