0

Im trying to change the information on each row depending on the result from the query. Im thinking that at the minute my problem is that I'm only returning the first result from the query into the result.

e.g. query returns row 1 with '1232' row 2 '1243' but result is only ever set to '1232'

I could be wrong but its why I'm here :)

3
  • Since you are proposing that your SQL might be wrong, can you post that too? If it contains sensitive information, feel free to dull it down. Commented Dec 6, 2010 at 20:21
  • 1
    Also, in my experience, it is much easier to simply have the lblstatus already in your gridview template, and rather than adding the control conditionally when each row is databound, simply changing it's contents when need be. Commented Dec 6, 2010 at 20:22
  • Here is the SQL: Dim statement As String = "select tblCustomer.customerID from tblCustomer INNER JOIN tblAccount ON tblCustomer.customerID = tblAccount.customerID INNER JOIN tblAccountStatus ON tblAccount.accountID = tblAccountStatus.accountID WHERE (tblAccountStatus.status = 'deactivated')" Commented Dec 6, 2010 at 20:51

1 Answer 1

2

You say that your SQL returns multiple rows, but are using the ExecuteScalar() to run it. ExecuteScalar will only return a single result, ie the first column of the first row. Sounds like you need to fill a datatable using a SQLDataAdapter or something else to do what you're looking for.

Also it would be beneficial if you included your SQL statement as rlb indicated.

Sign up to request clarification or add additional context in comments.

3 Comments

Okay ive tried this and still no joy. What am i doing wrong? Thanks Dim result As SqlDataReader = command3.ExecuteReader() While result.Read() Dim IDRes As String = CStr(result("customerID")) If IDRes = variable Then temp = "Yes" labelstatus.Text = temp Else temp = "No" labelstatus.Text = temp End If End While
Im sorry, couldnt get the pasted code to edit correct format :(
Karl, code in the comments will not format correctly, you'll need to edit the question up above for that. As for your current problem, I see that the function you pasted was grdView_RowDataBound, it would appear that the data has already been bound to the gridView, so why are you re-querying against the server? If it's already databound then you should be able to reference that databound object that's already in memory. I guess without knowing more about how you're program is structured and your intentions it's sort of difficult to recommend a solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.