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

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

36
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.Columns.Count to iterate through each column index.
e.Row.Item(index) to use as the parameter name - "@1", etc.
e.Row.Item(index).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 2084
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
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
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...
3
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...
6
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...
6
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...
3
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"...
1
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
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
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
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. ...
1
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.