473,657 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get column names via Me.RowChanging' s "e"?

36 New Member
I have written a chunk of code that automatically writes a SQL string, using parameters. The parameters themselves are easy, but getting the column names has been a problem.

Is possible to get column names from the "e" of the Me.RowChanging event? Otherwise, writing
Expand|Select|Wrap|Line Numbers
  1. "Insert Into TableName (each, column, name) Values (@0, @1, @2)" 
is going to be a bit more difficult.

The other pieces of information I have made use of are:

e.Row.Table.Col umns.Count to iterate through each column index.
e.Row.Item(inde x) to use as the parameter name - "@1", etc.
e.Row.Item(inde x).GetType to get the System.Type, which I convert into a System.DbType

I could write a class that holds the column names of the dateset I made in the designer, but that would be silly (and counter-productive, too). The names of the columns are already in the dataset!
Jun 25 '09 #1
2 2107
MessyHeart
3 New Member
Are you sure it's Me.Rowchanging? What's the instance type whose RowChanging event you are handling? Probably try to cast the sender object to the type and get the column name there.

However, the column name in the data table doesn't have to be same as the actual column name in the database

for eg., if the select query is: select dbColumn1 as DisplayColumn from Table, the column name from the datatable/dataset will be DisplayColumn. If you use this column name in your insert query, it will fail.
Jun 25 '09 #2
Infog
36 New Member
Thank you! I hadn't even thought of that.

At the moment, the dataset's column names are the same as the database column names. I have an ArrayList that stores a coding name and a database-use name for each table and an ArrayList that stores the names and connection strings for all the databases I connect to, so adding an ArrayList that stores coding-use/database-use column names for each database wouldn't be a problem.

Here is the start of the dataset code (just fyi):
Expand|Select|Wrap|Line Numbers
  1. Partial Class DataSet1
  2.     Partial Class JobsDataTable
  3.  
  4.         Private Sub JobsDataTable_RowChanging(ByVal sender As System.Object, ByVal e As System.Data.DataRowChangeEventArgs) Handles Me.RowChanging
And this is what I'll be using to solve my problem:
Expand|Select|Wrap|Line Numbers
  1.  ' My records for manipulation
  2.  Dim ds_Primary As DataSet1 = MDIParent1.DataSetMaster
  3.  
  4. ' Get each column name for this table
  5. For i = 0 To e.Row.Table.Columns.Count - 1
  6.         'Use the CodeReference to find which in-memory table I need
  7.         strSQL &= ds_Primary.Tables.Item(strCodeReference).Columns(i).ColumnName()
  8.         If i + 1 = e.Row.Table.Columns.Count Then
  9.                 ' Finish the column names, and move to the parameter names
  10.                 strSQL &= ") ("
  11.         Else
  12.                 ' Make way for the next column name
  13.                 strSQL &= ", "
  14.         End If
  15. Next i
  16.  
Jun 25 '09 #3

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

Similar topics

6
1852
by: Brad Kent | last post by:
Anyone out there have any tricks or scripts to take some text of unknown length and display it in two (or more) columns of equal height? The text may or may not contain "hard-coded" linebreaks or other formatting such as s. why there's not a columns tag in HTML is mystery <COLUMNS col=3> wouldn't this be grand </COLUMNS>
3
22626
by: Prince Kumar | last post by:
Is there any way I can define an Unique constraint or unique index which allows more than one null values for the same column combination in DB2? ie, If my index is defined on (col3, col4) where both columns allow nulls, I want col3 + col4 to be unique, if one or both the columns have values. If both columns have nulls, it should allow more than one such rows. ex,
6
1445
by: Larry Woods | last post by:
I am trying to name my submenus (MainMenu control) and they show up in the menu dropdown...like they are O.K., but when I check my controls the names are still "MenuItemX". OTOH, the top-level menu items renamed just fine. What might I be doing wrong? TIA, Larry Woods
6
10666
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the data on the datasource. It simply gets the first name and last name of an instructor and displays it in the grid. I have two major problems.... One, it doesn't display in the column until the row is saved, (Even after calling a refresh on the...
3
6637
by: Ed L. | last post by:
On 7.4.6, is there any problem with defining one column of a view to be a string literal? For example ... $ psql -c "create view fooview as select 'bar' as footype" WARNING: column "footype" has type "unknown" DETAIL: Proceeding with relation creation anyway. CREATE VIEW Or is this warning just noise in this case?
1
8213
by: Sandro Daehler | last post by:
Hy i have a problem with the following statement: SELECT MAX(id) FROM apconfig; if i send this statement i got the following error: ERROR: column "id" does not exist
17
4696
by: Darek | last post by:
Hi, I have a table, something similar to: create table my_table ( id char(32) not null primary key, num integer not null, code varchar(2) not null, name varchar(60) not null,
3
10358
by: Vivek | last post by:
Hi, Can someone give an example of a query which produces the following warning: SQL0012W Correlation without qualification has occurred for the column "<column>".
6
14376
by: crs27 | last post by:
Hai, Im getting this error.There is a column by name "nr_first_name" in the table "gistl_new_request". Yet im getting as that dose not exist.Would like to now what is the cause of it. Thank You
1
8649
by: JaganMohanRao | last post by:
i have create a table and inserted a values init. when i am getting the values it is throwing the exception "ERROR: column "dtype" of relation "xxxx" does not exist" where xxxx is table name. if any body knows the solution kindly help me Thanks in advance .. Jagan
0
8392
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, 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...
0
8825
Oralloy
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...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
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, 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...
1
6163
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 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...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.