cant populate comboboxes in XP

  • Thread starter Thread starter Mike Fellows
  • Start date Start date
M

Mike Fellows

when i load my windows form i populate a combobox i use the code below

Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim sql As String = "AllLenders"
Dim da As New System.Data.SqlClient.SqlDataAdapter(sql, conn)
Dim ds As New DataSet()
da.Fill(ds)
ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "Lender"
da.Dispose()
ds.Dispose()


This code compiles and works perfectly on my win2k box
now when someone takes my compiled executable and runs it on
windows xp, the combobox is not populated!

Ive also tried compiling it on a windows xp box and it still does not
work

the sql string is a stored procedure

im desperate for help with this as ive hit a brick wall!

Thanks

Mike Fellows
 
don't know if this is it but
you bind the combo to a dataset and then dispose the dataset
unles someone has a better sollution have a look in that direction

hope it helps

eric
 
Nah,

didnt make any difference not disposing of the dataset

so im still as stuck as i was before
 
Just out of curiousity, you are using strConn as the connection string for
your connection object. You don't display it here, perhaps for security
reasons, but my question is this.

Are you using a data source name on the 2K box that is not present on the XP
box? If your strConn is an actual connection string pointing to a DB,
ensure that the location and DB are the same on both systems.

One way to debug this real quick is to do a table count or a row count on
the table to see if you are returning any rows at all. This will narrow the
search as to where the problem lies, either DB connectivity or combo box
problem.

I'm inclined to believe that for some reason, you are not really connecting
to the DB.
 
my strconn looks like this

Dim strConn As String =
"server=Gringotts;uid=*****;pwd=*****;database=lender"

i did a row count on my dataset and both return me 10 rows

now im even more stuck as i now know the data is there just not filling the
combobox!

Mike
 
humor me ;) (i don't like bound combos they have given me to much nightmares
;) )
below is a small listitem class you could use (this has always worked for
me)

loop the dataset
'code
dim li as clslistitem
combobox1.items.clear()

for each dr as datarow in ds.tables(0).rows
li = new clslistitem()
li.text = dr(1) 'or dr("Lender")
li.Obj = dr
combobox1.items.add(li)
next
'end code

to use the cbo
dim li as clslistitem
li = combobox1.selecteditem
dim dr as datarow
dr = li.obj

'code
Public Class clsListItem

Private Tekst As String
Private objke As Object

Public Sub New()
Tekst = ""
objke = new Object
End Sub

Public Sub New(ByVal te As String)
Tekst = te
objke = new Object
End Sub



Public Property Text() As String
Get
Return Tekst
End Get
Set(ByVal Value As String)
Tekst = Value
End Set
End Property


Public Property Obj() As Object
Get
Return objke
End Get
Set(ByVal Value As Object)
objke = Value
End Set
End Property

Public Overrides Function ToString() As String
Return Tekst
End Function


End Class


Mike Fellows said:
my strconn looks like this

Dim strConn As String =
"server=Gringotts;uid=*****;pwd=*****;database=lender"

i did a row count on my dataset and both return me 10 rows

now im even more stuck as i now know the data is there just not filling the
combobox!

Mike


Gerry O'Brien said:
Just out of curiousity, you are using strConn as the connection string for
your connection object. You don't display it here, perhaps for security
reasons, but my question is this.

Are you using a data source name on the 2K box that is not present on
the
 
Hi Gerry,

I take your message to Help Mike, because the last sentence from your
message should throw a connection error if it is true, but because he can
probably not debug on the XP computer I find your idea of counting
intresting.

Hi Mike,

Can you add this after your strConn = etc and change the name of your
table?.

Dim myCommand As New SqlCommand("select count(*) from MyTable", strConn)
myCommand.Connection.Open()
Dim count As Integer = CInt(myCommand.ExecuteScalar())
messagebox.show(count.tostring)
Conn.Close()

I am also curious.

(By the way, can you tell why you dispose those resources of the dataset and
the dataadapter)

Cor
 
EricJ,

I cant get your code to work at all

i created the class with no problems

i then put the other code section into the onformload sub
but your for statement does not work and to be honest i cant read your code

but the main problem im still having is that my orignal code works fine in
win2k
but does not work in windows xp - i cant see why there should be a
difference
as fundementally the Os's are still the same.
 
EricJ

got it working (id missed a line - apologies)

it works fine in both XP and Win2k

Thanks for your help

Mike
 
Hi Mike,

But the suske and wiske class from Eric should not be necessary, this is
real strange.
Did you for the datarow use that dararow (1) or that "Lender"?

Cor
 
Cor,

I've already counted my rows from the dataset, and in both xp and 2k it
returned the correct value

I dispose of my dataadapter and my dataset as they are no longer used and I
presume they use memory
so I dispose of them for efficiency

Mike
 
hey cor :)

you are absolutely right, but
my colegues have had a lot of unexplainable bound combo problems. I got
everyone working w a bigger version of that 'suske and wiske' class and
since then no probs.
(I like to put a lot of things in there ;p )
 
Yes, I believe you are correct although I have seen situations where I
wasn't connected and also for some reason didn't get an error. Strange but
true.

At any rate, I have used the method of counting rows returned since I
started working with XML files as data sources. I find it a quick way to
determine if I am at least getting anything back.
 
This is bizarre. I can do a succesful display on 2K or XP.

--
Gerry O'Brien
Visual Developer .NET MVP



Mike Fellows said:
my strconn looks like this

Dim strConn As String =
"server=Gringotts;uid=*****;pwd=*****;database=lender"

i did a row count on my dataset and both return me 10 rows

now im even more stuck as i now know the data is there just not filling the
combobox!

Mike


Gerry O'Brien said:
Just out of curiousity, you are using strConn as the connection string for
your connection object. You don't display it here, perhaps for security
reasons, but my question is this.

Are you using a data source name on the 2K box that is not present on
the
 
Back
Top