?
Solved

Difficulty in Accessing ColumnName in a TypedDataset

Posted on 2007-11-26
20
Medium Priority
?
252 Views
Last Modified: 2013-12-16
I am having a severe problem accessing TypedDataset ColumnName to be passed as a parameter to my stored procedure

Below code I want to eliminate "Name" and put  TypedDataset ColumnName
    _Database.AddInParameter(InsertCommand, "@Name", DbType.string, "Name", DataRowVersion.Current);

VisualStudio.NET 2005 IDE --- TypedDataSet Name ----- CustomerDataSet   TableName:Customer
I wanted to pass as :  CustomerDataSet.Customer.Name but I dont get in my code. Any one had same issues.



0
Comment
Question by:dotnet0824
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 10
20 Comments
 
LVL 27

Expert Comment

by:VBRocks
ID: 20352227
You should be able to do it like this:

_Database.AddInParameter(InsertCommand, "@" & CustomerDataSet.Customer.Name.ColumnName", DbType.string, "Name", DataRowVersion.Current);


0
 
LVL 27

Expert Comment

by:VBRocks
ID: 20352232
Oops, remove the quote (") after CustomerDataSet.Customer.Name.ColumnName,



0
 

Author Comment

by:dotnet0824
ID: 20352261
CustomerDataSet  _dsCustomer= new CustomerDataSet();
_dsCustomer.Customer.NameColumn               /// I Only Get this
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 27

Expert Comment

by:VBRocks
ID: 20352291
You should be able to do it this way:
    _dsCustomer.Customer.NameColumn.ColumnName


0
 

Author Comment

by:dotnet0824
ID: 20352438
Nope I dont get it......U can try adding a TypedDataset to your Visual studio.NET 2005 Designer and check it out
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 20352464
Yes, I did, both in VB and C#, and it works fine.

This is straight out of my C# project, and it worked fine:

            CustomerDataSet _dsCustomer = new CustomerDataSet();
            System.Diagnostics.Debug.WriteLine  (_dsCustomer.Customer.NameColumn.ColumnName);

So, I'm not sure why it's not working for you.

Try using the ToString() method, that should return the column name as well:
            _dsCustomer.Customer.NameColumn.ToString()

0
 

Author Comment

by:dotnet0824
ID: 20352522
Though this is not related to the question.. (I found something weird when u add a typed Dataset and name the Dataset Same as TableName which u drag from the Server explorer in IDE )
lets say Customer Table is dragged and u name the TypedDataset Customer and when u try to refer it in ur code it take _Customer  (thats the reason I named the TypedDataset as CustomerDataset /Table name being Customer)
0
 

Author Comment

by:dotnet0824
ID: 20352603
Well I created a Project Named  (Class)

Biz.US
 Now I add New Item ---- Select Dataset  and Drag a Table - Customer from Server Explorer
I remove the DataAdapater in the Diagram as We dont need it as I am working on Code to populate it .
Every thing works fine but I cant access the ColumnNames directly

Now i Refer in my code  
Biz.US.CustomerDataSet.Customer.  like that
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 20352708
I was able to reproduce the situation, so I see what you are saying.

So can you get the column name now, or do you have to create an instance of it?
    Biz.US.CustomerDataSet.Customer.ColumnName

or
     Biz.US.CustomerDataSet _dsCustomer = new Biz.US.CustomerDataSet();
      _dsCustomer.Customer.NameColumn.ColumnName;
0
 

Author Comment

by:dotnet0824
ID: 20352828
ok now i use this   Biz.US.CustomerDataset in another Class like this
////////////////////////////////////////////////////////
using BIZ.US  (Imports in VB.NET) added a refernce of BIZ.US in this Class
  public int Add(Biz.US.CustomerDataSet dsCustomer)
        {
            try
            {
       BIZ.US.CustomerDataSet  dsCustomer = new BIZ.US.CustomerDataSet();
         dsCustomer.Customer.NameColumn.     (After this NameColum Dot I dont get Name)
         

             }
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 20352899
What options do you have in the drop down list when you type a period "." after
    dsCustomer.Customer.NameColumn?

0
 

Author Comment

by:dotnet0824
ID: 20353009
dsCustomer.Customer.NameColumn.AllowDBNull,
                                                           AutoIncrement,Caption,ColumnMapping,DataType,ColumnName

                     and other string functions Lenglth,Padleft,PadRight etc
 
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 20353035
So select the "ColumnName" property, like this:
    dsCustomer.Customer.NameColumn.ColumnName

0
 

Author Comment

by:dotnet0824
ID: 20353324
Is  dsCustomer.Customer.NameColumn.ColumnName   = dsCustomer.Customer.NameColumn.Name??
0
 

Author Comment

by:dotnet0824
ID: 20353589
No VBRocks...  its wrong

dsCustomer.Customer.NameColumn.                    (I have Name,Address,Active Fields)  I can see ColumnName common.......... I cant Refer  Name or address or Active
0
 
LVL 27

Accepted Solution

by:
VBRocks earned 2000 total points
ID: 20353713
In response to your first post:

"NameColumn" is the the actual column that is named "Name", and it is of type DataColumn.  

"ColumnName" is the name of the column, and it is of type "String".  It will return the name of the
    DataColumn.

In your last post, you still list "ColumnName" as one of the properties?

0
 

Author Comment

by:dotnet0824
ID: 20354285
Hi VbRocks,
We have to refer as

dsCustomer.Customer.NameColumn.ColumnName
dsCustomer.Customer.AddressColumn.ColumnName
dsCustomer.Customer.CityColumn.ColumnName  

I added a Quick watch while debugging on these and got them to be Name,Address and City
It works. Thanks  a lot.   My last question is   why doesnt it just take  Name, Address, City   any idea>
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 20354303
You can type it in, like your question demonstrated, this works fine:

    _Database.AddInParameter(InsertCommand, "@Name", DbType.string, "Name", DataRowVersion.Current);

    _Database.AddInParameter(InsertCommand, "@Address ", DbType.string, "Address ", DataRowVersion.Current);

    _Database.AddInParameter(InsertCommand, "@City", DbType.string, "City", DataRowVersion.Current);


0
 

Author Comment

by:dotnet0824
ID: 20354375
Hi Vbrocks yep i can do that

dsCustomer.Customer.NameColumn.ColumnName
dsCustomer.Customer.AddressColumn.ColumnName
dsCustomer.Customer.CityColumn.ColumnName  

Can I take these into variables and assign them in my parameters... if so could u please show me
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 20358399
Sure, here's an example:

'Create a variable to store the column names
Dim colName as String = ""

colName = dsCustomer.Customer.NameColumn.ColumnName
_Database.AddInParameter(InsertCommand, "@" & colName, DbType.string, colName,  
    DataRowVersion.Current);

colName = dsCustomer.Customer.AddressColumn.ColumnName
_Database.AddInParameter(InsertCommand, "@" & colName, DbType.string, colName,  
    DataRowVersion.Current);

colName = dsCustomer.Customer.CityColumn.ColumnName
_Database.AddInParameter(InsertCommand, "@" & colName, DbType.string, colName,  
    DataRowVersion.Current);


Good luck, and happy programming!



0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question