I know I can use dataviews and more looping to do this, but I'm
wondering if there's a more elegant or more concise way to do this.
I've got two DataTables with a column called guest_no. I'd love to be
able to use something like the .IndexOf method of arrays and bound
controls. Somehting like:
Dim r as DataRow
For Each r in DataTable2.Rows
If DataTable1.Colu mns("guest_no") .IndexOf(r("gue st_no")) <> -1
'record exists
'do something
Else
'record doesn't exist
'do something else
End If
End For
Is there anything like this? Obviously, the code above doesn't work.
Thanks,
Matt 2 7966
A column in a datatable is like a column in a table in your database. You
wouldn't expect the column definition to just have a value, would you? No.
You would expect a column (cell) in a particular row to have a value. Same
goes here.
Asking a column to have a value doesn't make sense semantically.
Something like:
DataTable1.Rows (0)("guest_no")
makes sense. That asks for the value of the guest_no column in the first
row.
Remember that this returns an Object, turn Option Strict On, and then type
this to the correct type - in your case a string.
"MattB" <so********@yah oo.com> wrote in message
news:3t******** ****@individual .net... I know I can use dataviews and more looping to do this, but I'm wondering if there's a more elegant or more concise way to do this.
I've got two DataTables with a column called guest_no. I'd love to be able to use something like the .IndexOf method of arrays and bound controls. Somehting like:
Dim r as DataRow For Each r in DataTable2.Rows If DataTable1.Colu mns("guest_no") .IndexOf(r("gue st_no")) <> -1 'record exists 'do something Else 'record doesn't exist 'do something else End If End For
Is there anything like this? Obviously, the code above doesn't work.
Thanks, Matt
Yes, I know. I was just looking for a shortcut for more concise code.
Something like how I can have an array and use the IndexOf method to
quickly know if a values exists and in what element if it does without
having to loop through the array, testing each element explicitly.
Thanks for the reply,
Matt
Marina wrote: A column in a datatable is like a column in a table in your database. You wouldn't expect the column definition to just have a value, would you? No. You would expect a column (cell) in a particular row to have a value. Same goes here.
Asking a column to have a value doesn't make sense semantically.
Something like:
DataTable1.Rows (0)("guest_no")
makes sense. That asks for the value of the guest_no column in the first row.
Remember that this returns an Object, turn Option Strict On, and then type this to the correct type - in your case a string.
"MattB" <so********@yah oo.com> wrote in message news:3t******** ****@individual .net...
I know I can use dataviews and more looping to do this, but I'm wondering if there's a more elegant or more concise way to do this.
I've got two DataTables with a column called guest_no. I'd love to be able to use something like the .IndexOf method of arrays and bound controls. Somehting like:
Dim r as DataRow For Each r in DataTable2.Rows If DataTable1.Colu mns("guest_no") .IndexOf(r("gue st_no")) <> -1 'record exists 'do something Else 'record doesn't exist 'do something else End If End For
Is there anything like this? Obviously, the code above doesn't work.
Thanks, Matt This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Woody Splawn |
last post by:
Lets say I have a winform that is populated with a dataset. The dataset and
data table may have several rows in it. Lets say I am looking at the
winform and I want to assign a value to a certain column in the associated
datatable. Lets say there are 10 rows in the table and I am on row 5, and I
want to assign the value to row 5, but I don't know that I am on row 5.
Anyway, my method for assigning the value to the field would be:
Dim Dt...
|
by: JC Voon |
last post by:
Hi:
How to reset the autoincrement value generated by DataTable ?
I've master and detail table, the detail table has a autoincrement
column, each time i add a new master record, i need to reset the
detail table autoincrement column to start from 1.
I set the dataColumn AutoIncrementSeed=0 and AutoIncrementStep=1 each
time i append a new master row, but it seem not work, it still remain
|
by: Matt |
last post by:
I derived my own custom class from the datagrid class.
I overrode the ProcessCmdKey Function, like this, to catch the up and down
arrow keys:
======
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal
keyData As Keys) As Boolean
Const WM_KEYDOWN As Integer = &H100
|
by: Niyazi |
last post by:
Hi all,
I have a dataTable that contains nearly 38400 rows.
In the dataTable consist of 3 column.
column 1 Name: MUHNO
column 2 Name: HESNO
Column 3 Name: BALANCE
Let me give you some example first:
|
by: RSH |
last post by:
Hi,
I have a situation where I have two datareaders, and I want to make sure any
given field from Datareader A exists in Datareader B before I can do
anything with that column.
I tried the code below but I get an exception thrown because the column
doesn't exist in Datareader B.
I'm not opposed to using another method but the same thing happened when
using a Dataset. How do I do this??
| |
by: RSH |
last post by:
Hi,
Iam struggling with an application where I am trying to transfer a datarow
from one sql server to another instance of sql server. The schmeas may be
slightly different and I am getting an exception when they are different.
Is there anyway i can modify the code below so that if the schemas are
different I can drop the offending column in the appropriate datatable?
Thanks,
Ron
|
by: neeraj |
last post by:
Hi Everybody
Is any body suggest me how can I get all cell value together(without
looping), from single column of datatable in asp.net like this
"Datatable.row (0).ItemArray"
This returns all column value of row 1 as an array
For exp. Datatable has data in this format
Column1 Column2
|
by: Maart_newbie |
last post by:
Hi all,
I've got a question about returning the value of a pk-column to a
DataTable
after inserting a row (via a data-adapter) using MySql5.
Here is the SQL and code concerned:
//===================================================================
// The table
|
by: =?Utf-8?B?UmljaCBIdXRjaGlucw==?= |
last post by:
I'm not really sure how to ask this question because I'm still getting my
feet wet with data access and VB.NET, but here goes:
To start off with, I'm using VB 2005 Express to connect to an Access database.
I have a dataset in which a parameterized query returns the correct result
set in the forms of a tableadapter and a bindingnavigator. In other words, I
can perform my query and see that the tableadapter and bindingnavigator
contain...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |