Results 1 to 3 of 3

Thread: assigning a database value to a string.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2004
    Posts
    29

    assigning a database value to a string.

    hi...

    can someone tell me how do i assign a value to a string to do further processing...so far i've done this

    Code:
    oleDbDonnection1.Open();
    
    oleDbDataAdapter.SelectCommand.CommandText = ......
    
    string UserType = (string) oleDbDataAdapter.SelectCommand.ExecuteScalar(); // is this correct...the usertype column is not the first column its the third column...
    
    UserType.ToString();
    Arvinder Gill

  2. #2
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    i dont know much about ado .net but wouldnt you fill a dataset an pull the value from it?

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    ExecuteScalar only returns one value, which is the first value in the first row of the result set that is returned from the query.

    So, if what you want is the third value in your query, you will never get it with ExecuteScalar.

    Either adjust your CommandText to get just the one value, or you need to ExecuteReader or ExecuteDataset and manually map to the column you are looking for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width