Solved

Difficulty in Accessing ColumnName in a TypedDataset

Posted on 2007-11-26
20
242 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
  • 10
  • 10
20 Comments
 
LVL 27

Expert Comment

by:VBRocks
Comment Utility
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
Comment Utility
Oops, remove the quote (") after CustomerDataSet.Customer.Name.ColumnName,



0
 

Author Comment

by:dotnet0824
Comment Utility
CustomerDataSet  _dsCustomer= new CustomerDataSet();
_dsCustomer.Customer.NameColumn               /// I Only Get this
0
 
LVL 27

Expert Comment

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


0
 

Author Comment

by:dotnet0824
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 27

Expert Comment

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

0
 

Author Comment

by:dotnet0824
Comment Utility
dsCustomer.Customer.NameColumn.AllowDBNull,
                                                           AutoIncrement,Caption,ColumnMapping,DataType,ColumnName

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

Expert Comment

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

0
 

Author Comment

by:dotnet0824
Comment Utility
Is  dsCustomer.Customer.NameColumn.ColumnName   = dsCustomer.Customer.NameColumn.Name??
0
 

Author Comment

by:dotnet0824
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now