473,394 Members | 1,956 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,394 software developers and data experts.

Executing a Query and updating a DataTable

Hi all,

I have the following query which I want to use to update a DataTable:
"SELECT
tblVmsResponse.IntDestZone,(tblVmsResponse.LngDest inationDiversionNum)
as Diversionnumber," & " (tblVmsResponse.strIncidentLink) as
Incidentlink ,(tblVmsResponse.bytMessageResponse) as response,
tblVmsResponse.strPlan" & " FROM (tblIncidentResponse INNER JOIN
tblVmsResponse ON
tblIncidentResponse.strLinkNum=tblVmsResponse.strI ncidentLink) INNER
JOIN" & " tblPlanVmsSetting ON tblPlanVmsSetting.strVmsId
=tblVmsResponse.strVmsId" & " WHERE ((tblVmsResponse.strVmsId = ?) AND
(tblPlanVmsSetting.strPlan =?) AND" & "
(tblPlanVmsSetting.strPlan=tblIncidentResponse.str Plan))" & " GROUP BY
tblVmsResponse.intDestZone,tblVmsResponse.LngDesti nationDiversionNum,"
& " tblVmsResponse.strIncidentLink,tblVmsResponse.bytM essageResponse,
tblVmsResponse.strPlan;"

I now want to be able to fill a DataTable and, at a later stage,
execute the above query with values for tblVmsResponse.strVmsId and
tblPlanVmsSetting.strPlan (which are currently unknown). I then want
to update the table based on the supplied values.

How can this be done?

Thanks in advance

Simon

Nov 21 '05 #1
1 1196

I've figured out how to do this now - but is there a better way?

The code is as follows:

Dim connectionString As String = "Provider =
Microsoft.Jet.OLEDB.4.0;Data Source = " & CDBPath() & TacCDBDB
Dim TacCDB As OleDbConnection = New
OleDbConnection(connectionString)
Dim DestSQL As String = "SELECT
tblVmsResponse.IntDestZone,(tblVmsResponse.LngDest inationDiversionNum)
as Diversionnumber," & " (tblVmsResponse.strIncidentLink) as
Incidentlink ,(tblVmsResponse.bytMessageResponse) as response,
tblVmsResponse.strPlan" & " FROM (tblIncidentResponse INNER JOIN
tblVmsResponse ON
tblIncidentResponse.strLinkNum=tblVmsResponse.strI ncidentLink) INNER
JOIN" & " tblPlanVmsSetting ON tblPlanVmsSetting.strVmsId
=tblVmsResponse.strVmsId" & " WHERE ((tblVmsResponse.strVmsId = ?) AND
(tblPlanVmsSetting.strPlan =?) AND" & "
(tblPlanVmsSetting.strPlan=tblIncidentResponse.str Plan))" & " GROUP BY
tblVmsResponse.intDestZone,tblVmsResponse.LngDesti nationDiversionNum,"
& " tblVmsResponse.strIncidentLink,tblVmsResponse.bytM essageResponse,
tblVmsResponse.strPlan;"
Dim Destcmd As OleDbCommand = New OleDbCommand(DestSQL, TacCDB)
Destcmd.Parameters.Add("@VMSID", OleDbType.VarWChar, 50,
"tblVmsResponse.strVmsId") '.Value = "0043A"
Destcmd.Parameters.Add("@PLANID", OleDbType.VarWChar, 50,
"tblPlanVmsSetting.strPlan") '.Value = "2C/110"
Dim DestAdp As New OleDbDataAdapter
DestAdp.SelectCommand = Destcmd
Dim DestTable As New DataTable
and then later on in the code I update the parameter values and re-fill
the datatable.

For v = 1 To Plan.VMSCount
Destcmd.Parameters.Item(0).Value() = MOLAVMSID(Plan.VMSIndex(v))
Destcmd.Parameters.Item(1).Value() = Plan.ID
DestAdp.Fill(DestTable)
Dim DestRows() As DataRow = DestTable.Select()

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Job Lot | last post by:
I have written 6 Queries in an Access DB, which are executed in a For Each…Next loop to populate DataSet object. A new DataTable object is created in DataSet for each query, as follows Private...
1
by: Luis Esteban Valencia | last post by:
Hello Everyone, Iam an intermediate ASP.Net programmer and iam facing a challenging task. I have a table in MS-SQL server database called 'Members'. The table has following fields... ...
2
by: susan.f.barrett | last post by:
Hi, Despite me being able to type the following in to SQL Server and it updating 1 row: > updatestockcategory 1093, 839 In my code, it is not updating any rows. dataSet = new DataSet();
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
3
by: Water Cooler v2 | last post by:
Dang! A *simple* query doesn't run on my machine. I wrote a Data Access Layer (DAL) in a dll that I am testing with the help of a console application. Here's the code. I am damn sure that my...
29
by: =?Utf-8?B?SGVybWF3aWg=?= | last post by:
Hello, Please anybody help me. I have only a little experience with web development. I created simple project using ASP NET 2.0 (VS 2005) It works fine on local computer. When I tried to run...
3
by: Oenone | last post by:
I have a project that creates a SqlDataAdapter and uses its Fill method to fill a DataTable with data from a user-provided query. From there I can obviously access details about the rows and...
1
by: joel | last post by:
hi guys... i am a student, i am studying and i am a newbie in VB.net and i am using SQL Server 2000. I have this datatable which i insert rows (may take up to 2 or more rows because i would...
0
LoanB
by: LoanB | last post by:
Hey guys need some info here. I am adding, updating and deleting data on a datagrid. I pass the datagrid's datasource (datatable dt) to my data layer. Assuming I have already created and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.