473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

IF statement is 'not working'

Hi,

I'm using the code underneath in a function:

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim ds As New DataSet
Dim dv As New DataView
Dim strMsg As String, strComputerName As String
Dim row As DataRow
Dim lngCurrentMachineTeller As Long, lngI As Long

cn.ConnectionString = oleDBConn1.ConnectionString
cn.Open()
rs = cn.OpenSchema(ADODB.SchemaEnum.adSchemaProviderSpe cific, ,
"{947bb102-5d43-11d1-bdbf-00c04fb92675}")
daAdapter.Fill(ds, rs, "USERS")
ds.Tables("USERS").Columns(0).ColumnName = "Computernaam"
ds.Tables("USERS").Columns(1).ColumnName = "Loginnaam"
ds.Tables("USERS").Columns(2).ColumnName = "Connected"
ds.Tables("USERS").Columns(3).ColumnName = "State"
dv.Table = ds.Tables("USERS")
dv.RowStateFilter = DataViewRowState.CurrentRows

For lngI = 0 To dv.Count - 1
row = dv.Item(lngI).Row
If row.Item("Computernaam").ToString = gsComputerName.ToString Then
msgbox("Same!")
Else
msgbox("Not the same!")
Endif
Next
The problem is strange behaviour in the line "If row.Item
("Computernaam").ToString = gsComputerName.ToString Then
". When in the command window I type: '?row.Item("Computernaam").ToString
= gsComputerName.ToString' it returns true. But when I debug the code
step by step it doesn't go into the if statement. Like it is 'not true'
suddenly. The variable 'gsComputerName' is a global string. They both
contain the same value but the IF STATEMENT "doesn;t work" for some
reason.

--
Met vriendelijke groet / With regards / Saludos,
Moviat Automatisering
Maurice Mertens
mauricem@moviat_KillSpamWordForEMail.nl

tel: +31 162 470 534
fax: +31 162 470 502
Nov 21 '05 #1
5 1393
this is really strange
" If row.Item("Computernaam").ToString = gsComputerName.ToString Then"
do you mean
" If row.Item("Computername").ToString = gsComputerName.ToString Then"??

be careful of spelling ("Computername")

Galin Iliev

"Maurice Mertens" <hm*****@nospam.nospam> wrote in message
news:Xn***************************@194.109.133.133 ...
Hi,

I'm using the code underneath in a function:

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim ds As New DataSet
Dim dv As New DataView
Dim strMsg As String, strComputerName As String
Dim row As DataRow
Dim lngCurrentMachineTeller As Long, lngI As Long

cn.ConnectionString = oleDBConn1.ConnectionString
cn.Open()
rs = cn.OpenSchema(ADODB.SchemaEnum.adSchemaProviderSpe cific, ,
"{947bb102-5d43-11d1-bdbf-00c04fb92675}")
daAdapter.Fill(ds, rs, "USERS")
ds.Tables("USERS").Columns(0).ColumnName = "Computernaam"
ds.Tables("USERS").Columns(1).ColumnName = "Loginnaam"
ds.Tables("USERS").Columns(2).ColumnName = "Connected"
ds.Tables("USERS").Columns(3).ColumnName = "State"
dv.Table = ds.Tables("USERS")
dv.RowStateFilter = DataViewRowState.CurrentRows

For lngI = 0 To dv.Count - 1
row = dv.Item(lngI).Row
If row.Item("Computernaam").ToString = gsComputerName.ToString Then
msgbox("Same!")
Else
msgbox("Not the same!")
Endif
Next
The problem is strange behaviour in the line "If row.Item
("Computernaam").ToString = gsComputerName.ToString Then
". When in the command window I type: '?row.Item("Computernaam").ToString
= gsComputerName.ToString' it returns true. But when I debug the code
step by step it doesn't go into the if statement. Like it is 'not true'
suddenly. The variable 'gsComputerName' is a global string. They both
contain the same value but the IF STATEMENT "doesn;t work" for some
reason.

--
Met vriendelijke groet / With regards / Saludos,
Moviat Automatisering
Maurice Mertens
mauricem@moviat_KillSpamWordForEMail.nl

tel: +31 162 470 534
fax: +31 162 470 502

Nov 21 '05 #2
No,

ds.Tables("USERS").Columns(0).ColumnName = "Computernaam"
The columnname is "Computernaam".

But it is very strange that in the command window the comparison returns
true and in my code the IF statement returns false for exactly the same
comparison. I also did a reboot of my PC which didn't change this result (I
don't know if I would feel more relieved when the results were in fact
different after the reboot :)..)


"Galin Iliev" <iliev@_NOSPAM_.Galcho.com> wrote in
news:eV**************@TK2MSFTNGP14.phx.gbl:
this is really strange
" If row.Item("Computernaam").ToString = gsComputerName.ToString Then"
do you mean
" If row.Item("Computername").ToString = gsComputerName.ToString
Then"??

be careful of spelling ("Computername")

Galin Iliev

Nov 21 '05 #3
Maurice,

Why do you than not set temporaly these two instructions in your code
dim a as string = row.Item("Computernaam").ToString
dim b as string = gsComputerName.ToString
For lngI = 0 To dv.Count - 1
row = dv.Item(lngI).Row
dim a as string = row.Item("Computernaam").ToString
dim b as string = gsComputerName.ToString
If row.Item("Computernaam").ToString = gsComputerName.ToString Then
msgbox("Same!")
Else


Than it is so easy to see when you debug step by step.

Just my thought,

Cor
Nov 21 '05 #4
Hi Cor,

I already tried your example but this also didn't work. The same problem!
After a little research we found the reason for this behaviour. The value
row.item("Computernaam") contains a string which came from the kernel.
These strings are ended with asci character 0. So we now use a replace
and a trim: Replace(Trim(row.Item("Computernaam")), Chr(0), "") and this
is working fine now!

Thx for looking at this problem..

"Cor Ligthert" <no************@planet.nl> wrote in news:#EpK$gcRFHA.204
@TK2MSFTNGP15.phx.gbl:
Maurice,

Why do you than not set temporaly these two instructions in your code
dim a as string = row.Item("Computernaam").ToString
dim b as string = gsComputerName.ToString
For lngI = 0 To dv.Count - 1
row = dv.Item(lngI).Row


dim a as string = row.Item("Computernaam").ToString
dim b as string = gsComputerName.ToString
If row.Item("Computernaam").ToString = gsComputerName.ToString Then msgbox("Same!")
Else


Than it is so easy to see when you debug step by step.

Just my thought,

Cor


--
Met vriendelijke groet / With regards / Saludos,
Moviat Automatisering
Maurice Mertens
mauricem@moviat_KillSpamWordForEMail.nl

tel: +31 162 470 534
fax: +31 162 470 502
Nov 21 '05 #5
Maurice,

Really a terrible situation to find.

From this newsgroup side I would probably never thought about that when you
had not told it now.

Thanks that you told what it was and congratulated as well with that.

Cor
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Tilley - HPC:Factor | last post by:
Hi, I'm utterly confounded by this one. There must be some sort of rule that I don't know of. I'd consider myself a Newbie+1, so be gentle. I have a database connection (working A-Ok) and a...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
1
by: mirandacascade | last post by:
O/S: Windows 2K Vsn of Python: 2.4 Currently: 1) Folder structure: \workarea\ <- ElementTree files reside here \xml\ \dom\
6
by: Doohan W. | last post by:
Hi, I'm now working with DB2, and I can't find out how to execute the contents of a string Statement, without using a Java/... procedure, only using SQL statements. I know that some SQBDs such...
7
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And...
4
by: kathy | last post by:
Working in a form, I have an Iif statement where if a date is not filled in, another field will show as a blank. If the date IS filled in, the 2nd field will show its actual value. The following...
3
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using...
14
by: Matt | last post by:
I need to add the following variable into an SQL statement and not sure how to do it. strGCID needs to be inserted into the following statement: SQL = "SELECT tblContacts.* FROM tblContacts...
2
by: travhale | last post by:
in a new project using .net 2005, c#. getting err message "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." source RDBMS is oracle 8i. I add a new...
2
by: iulian.ilea | last post by:
What is wrong int this SQL statement? select top 10 DOCInt.*, DOCDet.* , Cate.*, Arti.*, .* from DOCInt INNER JOIN DOCDet ON DOCInt.CodDoc=DOCDet.CodDoc LEFT JOIN Cate ON...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.