Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Problem with List Box

Author  Topic 

vk18
Posting Yak Master

146 Posts

Posted - 2006-11-02 : 12:07:26
Hello Friends,

I am trying to fill the list box with multiple values when i search with id, but it is not working. here is my code.
can you guys tell me what am i doing wrong..? Appreciate your help
Thx



Dim dbFunctions As New DatabaseUtilities
Dim sql As String
Dim objDataRow As DataRow


sql = "SELECT * FROM tblsubgroups where ckid = '" & subgroupid & "'"
objDataRow = dbFunctions.GetSQLDataRow(CONNECTIONSTRING, sql)

If objDataRow("description") Is DBNull.Value Then
Else
Me.lstsubgroup.SelectedValue = objDataRow("description")
End If
end sub

Kristen
Test

22859 Posts

Posted - 2006-11-02 : 12:13:16
What happens if you query the database with:

SELECT * FROM tblsubgroups where ckid = 'MySubGroupID'

from, say, Query Analyser?

By the by, you should name the columns instead of "SELECT *" - presumably you only want two columns for your SELECT list?

If someone adds a TEXT column (or several TEXT columns!!) to that table in the future you will be bringing back shed-loads of data that your application doesn't use, and it will crucify your performance - and you'll be searching for, and fixing!, all the SELECT * code for days, weeks and maybe years!

Kristen
Go to Top of Page

vk18
Posting Yak Master

146 Posts

Posted - 2006-11-02 : 12:39:21
quote:
Originally posted by Kristen

What happens if you query the database with:

SELECT * FROM tblsubgroups where ckid = 'MySubGroupID'

from, say, Query Analyser?

By the by, you should name the columns instead of "SELECT *" - presumably you only want two columns for your SELECT list?

If someone adds a TEXT column (or several TEXT columns!!) to that table in the future you will be bringing back shed-loads of data that your application doesn't use, and it will crucify your performance - and you'll be searching for, and fixing!, all the SELECT * code for days, weeks and maybe years!

Kristen




Hi,
In Query Analyzer it is working fine. It is just that list box is not displaying the multiple items in it.
Also there are only 2 columns in this table so i don't need to worry about using Select *

Thx
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-11-02 : 13:18:45
"In Query Analyzer it is working fine. It is just that list box is not displaying the multiple items in it."

Then the problem is in your application logic that displays the data

"Also there are only 2 columns in this table so i don't need to worry about using Select *"

Don't be so naive, you most certainly do.

Kristen
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-11-02 : 13:34:37
quote:
Originally posted by vk18

Hello Friends,

I am trying to fill the list box with multiple values when i search with id, but it is not working. here is my code.
can you guys tell me what am i doing wrong..? Appreciate your help
Thx



Dim dbFunctions As New DatabaseUtilities
Dim sql As String
Dim objDataRow As DataRow


sql = "SELECT * FROM tblsubgroups where ckid = '" & subgroupid & "'"
objDataRow = dbFunctions.GetSQLDataRow(CONNECTIONSTRING, sql)

If objDataRow("description") Is DBNull.Value Then
Else
Me.lstsubgroup.SelectedValue = objDataRow("description")
End If
end sub



The main thing you are doing wrong is not using parameters. Never concatenate together your sql like that; always use stored procedures and/or parameterized queries.

See: http://weblogs.sqlteam.com/jeffs/archive/2006/07/21/10728.aspx




- Jeff
Go to Top of Page

vk18
Posting Yak Master

146 Posts

Posted - 2006-11-02 : 14:21:06
quote:
Originally posted by Kristen

"In Query Analyzer it is working fine. It is just that list box is not displaying the multiple items in it."

Then the problem is in your application logic that displays the data

"Also there are only 2 columns in this table so i don't need to worry about using Select *"

Don't be so naive, you most certainly do.

Kristen



Hi,
I this is my logic which i already mentioned.This logic just works fine with text boxes and dropdowns but not working for this list box.
Even i tried with the column names instead of select *
Thx

Dim dbFunctions As New DatabaseUtilities
Dim sql As String
Dim objDataRow As DataRow


sql = "SELECT * FROM tblsubgroups where ckid = '" & subgroupid & "'"
objDataRow = dbFunctions.GetSQLDataRow(CONNECTIONSTRING, sql)

If objDataRow("description") Is DBNull.Value Then
Else
Me.lstsubgroup.SelectedValue = objDataRow("description")
End If
end sub
Go to Top of Page

KenW
Constraint Violating Yak Guru

391 Posts

Posted - 2006-11-03 : 13:18:36
I'm not sure, but I don't think you can use DataRow like you are. According to the .NET docs, a DataRow represents the rows in a DataTable; it doesn't look like you can use it on its' own like you are above.
Go to Top of Page
   

- Advertisement -