Solved

Difficulty in Accessing ColumnName in a TypedDataset

Posted on 2007-11-26
20
247 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
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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

16 Experts available now in Live!

Get 1:1 Help Now