User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,531 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,890 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2321 | Replies: 5
Reply
Join Date: Sep 2007
Posts: 81
Reputation: justapimp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

Need help passing database column value to a string variable.

  #1  
Oct 5th, 2007
I have a data table adapter that returns a single column and I would like to assign the column to a string variable. Can anyone help me on this. it seems very simple but when I use this syntax
GpsitDataTableAdpater provider = new GpsitDataTableAdapter();
string CarrierString = Convert.ToString(provider.getProviderByDevUID(1789));
it returns the table title "DEVICE". when I test the select statement, I get the right column but, when I used in the context above, I get the table's title.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Location: England
Posts: 156
Reputation: ptaylor965 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 19
Sponsor
ptaylor965's Avatar
ptaylor965 ptaylor965 is offline Offline
Junior Poster

Re: Need help passing database column value to a string variable.

  #2  
Oct 6th, 2007
Hi,
This is how i do it for SQL databases
Dim SQLda as New SQLDataAdapter
Dim SQLTable as new Data.DataTable
Dim SQLRow as Data.DataRow
Dim Value as String

SQLda = New SQLDataAdapter(SQL_SELECT_STATEMENT, CONNECTION_STRING)
SQLDA.Fill(SQLTable)

For Each SQLRow in SQLTable.Rows
    Value = SQLRow(Column_Name).toString
Next
Peter Taylor
Visual Basic.NET Application Developer

TaylorsNet
http://www.taylorsnet.co.uk
Reply With Quote  
Join Date: Sep 2007
Posts: 81
Reputation: justapimp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

Help Re: Need help passing database column value to a string variable.

  #3  
Oct 16th, 2007
Is there another implementation that works better with C#'s table data adapters. I tried your recommendation and it did not work for me.
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Need help passing database column value to a string variable.

  #4  
Oct 16th, 2007
Are you needing to keep the values in a data table or are you pulling them to use as an array? What exactly are you needing, if you can post it!
Reply With Quote  
Join Date: Sep 2007
Posts: 81
Reputation: justapimp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

Re: Need help passing database column value to a string variable.

  #5  
Oct 16th, 2007
I want to use them as an array that I can iterate through and Possibly produce different output. For example let say my my database content looks something like this.
Column StartDateTime = 2007-12-12 11:00:00:000
Column EndDateTime = 2007-12-17 04:00:00:000
Column TimeZone = 3

I would like to evaluate the value for the TimeZone and subtract or add the value to the StartDateTime and EndDateTime.

If I can load the values into an array, I can use a foreach statement to do the mathematical operation and return and return the datatable to be binded to a formview later.


Thank you for responding.
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Need help passing database column value to a string variable.

  #6  
Oct 20th, 2007
well I am not a C# man, infact I have never used it besides for helping those with problems on this and other forums. Sorry for the late response. I can do it in VB and use www.codechanger.com to change it to C#. Below is the C# code I would use, and use a reader, not a datatable unelss you need updating. It's quicker and more efficient:
void Page_Load(Object s, EventArgs e) {
    SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["con"]);
    SqlCommand cmd = new SqlCommand("SELECT COMMAND OR STORED PROCEDURE NAME",con);
    //Use below line if stored procedure
    //cmd.CommandType = CommandType.StoredProcedure;

    con.Open();
    
    ArrayList arr = new ArrayList();
    SqlDataReader dr = cmd.ExecuteReader();
        
    while(dr.Read()) {
        object[] values = new object[dr.FieldCount];
        dr.GetValues(values);
        arr.Add(values);
    }

    dr.Close();
    con.Close();
}
Last edited by SheSaidImaPregy : Oct 20th, 2007 at 2:59 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 4:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC