why is this code not working? - vb6

I wonder why this code is not working?
ListView1.ListItems.Clear
' Set RS = New ADODB.Recordset
RS.Open "select nom, note, remarque from table1 WHERE remark=''", DB,
adOpenDynamic, adLockOptimistic
ListView1.View = lvwReport
Dim Lst As ListItem
Do While Not RS.EOF
Set Lst = ListView1.ListItems.Add(, , RS!nom)
Lst.SubItems(1) = RS!note
Lst.SubItems(2) = RS!remark
RS.MoveNext
Loop
End If
would anyone help, and correct me the code
I want to retrieve from the dtabase access the records that do not have remark

While, as joehanna has remarked, you haven't explained what your problem is, I'll put on my tinfoil hat, cross my legs, and chant for a few minutes and see if I can get any psychic impressions of what it is that you need...
Ah. It looks like you are trying to get all records which have no remark in them, and you aren't getting any of them. (Of course, you haven't mentioned whether you're getting any of them or not, which is why I have to resort to my tinfoil hat. It would be much better if you would simply tell us, instead of just saying that the code isn't working.) This is probably because you are asking for all records where remark has an empty string, and there aren't any.
Typically, if there is no value in a field in a database, the field has the value of NULL. (Sometimes imported data puts empty strings in fields instead of null values, but usually not.) I'm going to guess that your problem is that you are looking for an empty string, and the actual value that you need to be looking for is NULL. If so, I'll let you work out the actual WHERE clause.

Thank you everyone. My problem is solved.
I'm sorry because it was a stupidity my part.
I used to fill the fields manually on my table which does not give the ppropriate results for my query.
When I deleted all the fields and I filled the texts via the form all became great
thank you again and I apologize

Related

Google Sheets Query Sorted Results

I am writing a query function that I would like sorted. I have this figured out. What I cannot solve is attempting to insert 2 blank rows between the sorted results. Is this at all possible? Here is my query as it currently stands. Works perfectly as written. Just would like to have a 2 row gap between results.
Thank you.
=query('Form Responses 1'!A:CM,"Select B,C,D,I,L,AU,AX Where K = '"&Titles!B2&"' OR AW = '"&Titles!B2&"'Order by K,AW",0)
enter image description here
Since you've clarified your question to say that you want two blank rows, only to be added at a specific point in your query results, I've created another answer. But you haven't answered my question about what criteria you have for deciding where to insert these two lines, so I've made an assumption based on your data. This formula should be easily adapted if you have some other criteria for where to insert the blank lines. See my added tab HelpGK in yur sample sheet.
Try this formula, where you have your query:
={query('Data Sheet'!A:J,"Select B,C,D,E,F,H,I Where E='' and (G = 'ABC' OR J = 'ABC') Order by J,G",0);
{"","","","","","",""};
{"","","","","","",""};
query('Data Sheet'!A:J,"Select B,C,D,E,F,H,I Where E<>'' and (G = 'ABC' OR J = 'ABC') Order by J,G",0)}
Note that I don't believe your exact Desired Result can be obtained from your Data sheet. You are missing data rows. But this formula produces the result in the screenshot you provided.
EDIT:
Just realised that I created an answer for a single column of data.
Please share a sample sheet since this is not your case.
You can try this formula, but you'll need to replace this text "A4:A8" with your exact query:
=ArrayFormula(flatten(split(A4:A8 & "♥ ♥ ","♥",0,0)))
Note that the column with the "~" values in the blank cells is just to demonstrate what is happening.
If you had provided a sample sheet, with sample data, it would have been easier.
Let me know if this works for you. If not, please provide a sample sheet, with sample data, and let us know what else you need.
Be aware that the you can't put any values into the two inserted rows of blank cells, or the arrayformula will fail. But if you are planning to save the results of this as values, then pasted into place, then you could overwrite the blank cells, if desired.
Also be aware that FLATTEN is an undocumented function, and may possibly be removed from Sheets. If this is for a critical application, and alternative formula can be provided. Let us know if that is a concern.
I will delete my earlier answer, which mistakenly focused on a one column result.
This messy formula seems to handle multiple columns. If it works for you, I'll see if I can simplify it or clean it up. I can also provide details of the steps it is doing, if necessary. Replace the text "A4:C8" in this formula with the range where your query result currently exists. Once you've tested that, you can replace the text "A4:C8" with your actual query statement, to have everything done in one formula, if you want.
=ARRAYFORMULA(SUBSTITUTE(SUBSTITUTE(SPLIT(FLATTEN(ARRAYFORMULA(SPLIT(TRANSPOSE(ARRAYFORMULA(QUERY(TRANSPOSE(ARRAYFORMULA(SUBSTITUTE(A4:C8," ","♥"))),,99^99)&"♦~♦~")),"♦",1,0)))," ",1,0),"~",""),"♥"," "))
Please let me know if this works for you. If you have any issues, please share a sample sheet, with only sample data, and clarify what isn't working as you expect.

BIRT Before Open value list params errors

I have a (semi) basic data cube set up with a cascading parameters of State and Area. The state select box is straight forward as is the Area; when a user selects a State, the Area options are set accordingly. However, the value for Area is a long list of strings that will be sent to the mysql select statement which will use both params (State & the list of strings from Area) several time. Its a big ugly collection of UNIONS. My problem is somewhere between the before Start and query time.
//beforeOpen script...LState & LAreas the name of the report param
this.queryText = this.queryText.replace('stateList', params["LStates"].value);
this.queryText = this.queryText.replace('areaList', params["LAreas"].value);
In my mysql statement I use them in the following way:
SELECT ..XXX..
FROM ..XXX..
WHERE ..XXX..
State.State_Location in ('stateList')
AND Range_Locator.Range in ('areaList')
UNION ALL
SELECT ..XXX..
FROM ..XXX..
WHERE ..XXX..
State.State_Location in ('stateList')
AND Range_Locator.Range in ('areaList')
The two errors I get from BIRT are:
(Pretty obvious)
Cannot get the result set. org.eclipse....SQL statement doesn ot return a ResultSet object.
(Not so obvious to me)
A BIRT exception occured. Error evaluating Javascript expression. Script engine error: Can't find method java.lang.String.replace(string.java.lang.Object[]).
There are error evaluating script "this.queryText = this.queryText.replace('stateList', params["LStates"].value);this.queryText = this.queryText.replace('areaList', params["LAreas"].value);"
Any ideas? Any help would be greatly appreciated.
It seems LStates is defined as a "multi-value" parameter, therefore params["LStates"].value returns an array of values: this is why this replace method does not work.
You should try like this:
this.queryText = this.queryText.replace('stateList', params["LStates"].value.join("','"));
I am not exactly sure what you are doing in beforeOpen script, but your SQL is looking for the string values 'stateList' & 'areaList' and is probably not happy about the (). You need to use question marks to call the parameters you define in the 'parameters' you set up in the data set design.
SELECT ..XXX..
FROM ..XXX..
WHERE ..XXX..
State.State_Location in ?
AND Range_Locator.Range in ?
UNION ALL
SELECT ..XXX..
FROM ..XXX..
WHERE ..XXX..
State.State_Location in ?
AND Range_Locator.Range in ?
I don't recall using
in ?
In any queries, I usually try and set it to use
like ?
There are number of issues in sending multiple choice parameters to SQL via BIRT. you might want to look at How do I set a parameter to a list of values in a BIRT report? There are also some security concerns. When I have to filter on multiples, I usually do it in a filter (data set design option) after the SQL has run. Thought this can be a resource problem if your SQL returns lots of values.
Thanks for the replies but since I was unable to get these options to work, I wound up restructuring the database & sql statements to run better. To address some previous suggestions:
#dom the states parameter has only one value and while using "IN ('stateList')" is not efficient (disclaimer, not my code) adding the .join(',') did throw an error specific to that; I tried and mysql/BIRT seemed to be expecting a comma separated list but got a string with a trailing comma.
#James I tried using the question mark (?) instead of the 'stateList' & 'areaList' but I think mysql/BIRT was not able to recognize which value went with which question mark...not too sure though since I was not able to debug well enough and find out exactly why. Could be a form to param mapping issue that I didn't notice. Thanks for the help.

Recordset .value property

Please see the DDL below:
CREATE TABLE TestDate (bookingdate datetime)
INSERT INTO TestDate VALUES ('2013-10-04')
Please see the ADODB recordset below:
rs.open "SELECT bookingdate FROM TestDate"
If rs("bookingdate") > dateadd("yyyy", -6, Now)
msgbox("test")
end if
What is the difference between specifying rs("bookingdate") and rs("bookingdate").value. I have read some questions on here where answerers say always use .value, but it is not explained why. I had a look on MSDN but could not find an answer.
Value is the default property of the Field object, so in VB6 there is no difference between rs("bookingdate") and rs("bookingdate").value when used without Set.
I personally prefer not using default properties that don't take parameters. It makes the code less confusing IMO.
In VB.NET the default property must have a parameter, so this situation does not occur.
Note Recordset has such default property with parameter, and you are using it to return the Field object: rs("bookingdate") is actually rs.Item("bookingdate"). Using those, IMO, makes no harm.

if..if else..else..in linq to objects

Given a DataView that contains multiple rows, I want to extract a row based on the following criteria;
If a row starts with a certain string and ends with a certain string, then choose that row above all others
If no rows meet the first criteria, then just look for a row that start with the certain string
If we can't match any of the above, default to null.
My quick attempt simply returns the first row that meets any criteria (excuse me if the VB syntax isn't right, I'm not that familiar with it);
Dim result = (From row In dv.Table.Rows() _
Where (GetString(row, "id").StartsWith(Me.ID.Substring(0, 3), StringComparison.OrdinalIgnoreCase) AndAlso _
GetString(row, "id").EndsWith(Me.ID.Substring(Me.RegisteredID.Length - 2, 2), StringComparison.OrdinalIgnoreCase)) OrElse _
GetString(row, "id").StartsWith(Me.ID.Substring(0, 3), StringComparison.OrdinalIgnoreCase) _
Select row).FirstOrDefault()
Edit: I meant to add that something like https://stackoverflow.com/a/443055/685760 looks promising, but I don't think it will work in my situation. Feel free to correct me if I'm wrong.
It would be difficult, if not impossible, to express that kind of algorithm in a query. A query will only judge each row independantly from the others.
You need to have the resultset of the first criteria before you can check for the second...
In my opinion you need to do three separate queries (which might just be ending up executing only the first one if it returns any result, since at that point you met your first criteria and do not need to check for other results).
The other way would be, I guess, through some kind of ranking of the data, but you might end up with something less clear AND less performant.
In any case, your code will be a hundred times more readable for common mortals, even if there was a way to express your needs in a query. There is such a thing as overuse of Linq ;)

LINQ group by question

I started playing around with Linq today and ran into a problem I couldn't find an answer to. I was querying a simple SQL Server database that had some employee records. One of the fields is the full name (cn). I thought it would be interesting to group by the first name by splitting the full name at the first space. I tried
group by person.cn.Split(separators)[0]
but ran into a lengthy runtime exception (looked a lot like a C++ template instantiation error).
Then I tried grouping by a few letters of the first name:
group by person.cn.Substring(0,5)
and that worked fine but is not what I want.
I'm wondering about two things:
Why does the first example not work when it looks so close to the second?
Knowing that behind the scenes it's SQL stuff going on, what's a good way to do this kind of thing efficiently
Thanks,
Andrew
Split has no translation into SQL.
So, how to do this string manipulation without split? Cheat like hell (untested):
string oneSpace = " ";
string fiftySpace = " ";
var query =
from person in db.Persons
let lastname = person.cn.Replace(oneSpace, fiftySpace).SubString(0, 50).Trim()
group person by lastname into g
select new { Key = g.Key, Count = g.Count };
The reason your first attempt didn't work is because LINQ to SQL uses Expression Trees to translate your query into SQL. As a result any code that isn't directly translatable into SQL is an exception - this includes the call to Split.
Thanks guys, I'll try the "Replace" trick to see if that runs. I'm very intrigued by LINQ but now it looks like there's some hidden mysteriousness where you have to know what your LINQ queries translate into before being able to use it effectively.
The core problem is of course that I don't know SQL very well so that's where I'll start.
Edit:
I finally tried the "Replace" today and it works. I even got to sort the grouped results by count so now I have a pareto of name in my company. It's horrendously slow, though. Much faster to select everything and do the bucketing in C# directly.
Thanks again,
Andrew

Resources