944,079 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 5096
  • ASP.NET RSS
Oct 5th, 2007
0

Need help passing database column value to a string variable.

Expand Post »
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
ASP.NET Syntax (Toggle Plain Text)
  1. GpsitDataTableAdpater provider = new GpsitDataTableAdapter();
  2. 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.
Similar Threads
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
justapimp is offline Offline
87 posts
since Sep 2007
Oct 6th, 2007
0

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

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
Reputation Points: 16
Solved Threads: 19
Junior Poster
ptaylor965 is offline Offline
169 posts
since Oct 2006
Oct 16th, 2007
0

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

Is there another implementation that works better with C#'s table data adapters. I tried your recommendation and it did not work for me.
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
justapimp is offline Offline
87 posts
since Sep 2007
Oct 16th, 2007
0

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

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!
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Oct 16th, 2007
0

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

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.
ASP.NET Syntax (Toggle Plain Text)
  1. Column StartDateTime = 2007-12-12 11:00:00:000
  2. Column EndDateTime = 2007-12-17 04:00:00:000
  3. 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.
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
justapimp is offline Offline
87 posts
since Sep 2007
Oct 20th, 2007
0

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

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:
ASP.NET Syntax (Toggle Plain Text)
  1. void Page_Load(Object s, EventArgs e) {
  2. SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["con"]);
  3. SqlCommand cmd = new SqlCommand("SELECT COMMAND OR STORED PROCEDURE NAME",con);
  4. //Use below line if stored procedure
  5. //cmd.CommandType = CommandType.StoredProcedure;
  6.  
  7. con.Open();
  8.  
  9. ArrayList arr = new ArrayList();
  10. SqlDataReader dr = cmd.ExecuteReader();
  11.  
  12. while(dr.Read()) {
  13. object[] values = new object[dr.FieldCount];
  14. dr.GetValues(values);
  15. arr.Add(values);
  16. }
  17.  
  18. dr.Close();
  19. con.Close();
  20. }
Last edited by SheSaidImaPregy; Oct 20th, 2007 at 2:59 pm.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: how to transfer large data to one page to another page
Next Thread in ASP.NET Forum Timeline: Cross page posting confusion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC