I have listbox with 1 columns populated with an Oracle based ADODB Recordset using
strsql = "SELECT '£' || expected_cost as ""Cost"""
lstComm.RowSourceType = "Table/Query"
Set lstComm.
Recordset = rs
The query returns £1.58, but the listbox displays #1.58.
If I use
strsql = "trim(TO_CHAR(round(expected_cost,2), 'L9999999999999.99')) as ""Cost"""
The query returns £1.58, but the listbox displays $1.58.
Is there a way to populate the column as UK currency, whilst keeping the RowSourceType as "Table/Query"?
Simple answer: Yes.
The easiest (and best) way to accomplish this is to use a Currency format type. From there you just change the Format field from Currency to £#,##0.00;(£#,##0.00)
Related
I have one Table called tblEmployees - ID, First, Last. One unbound form called frmSearch with a textbox named Searchbox and a search button that searches by ID.I have one more unbound form called frmDisplay that displays the search result in it which I would like to edit when necessary. The textbox fields for this form are EID, Fname, Lname.
The problem I am having is when I enter the ID# in the searchbox and click the search button (where I linked both ID fields in the button wizard) it keeps on displaying the second record in my table. This is the code I currently have running
Private Sub Form_Load()
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("SELECT * from tblEmployees WHERE ID=ID")
EID.Value = rst!ID
Fname.Value = rst!First
Lname.Value = rst!Last
end sub
When I change the code to read
("SELECT * tblEmployees WHERE ID=" & ID")
I get a syntax error missing operator in query expression ID="
ID must have some value. Then concatenate ID:
"Select * From tblEmployees Where ID = " & ID & ""
The recordset that's currently being opened will include all the records in your table, because for every record the condition ID = ID will always be true. It's purely coincidence that it's displaying the second record from your table. You didn't specify a sort on the recordset query so it could randomly pick up any record as the first one in the results. What you actually need is
Set rst = CurrentDb.OpenRecordset("SELECT * from tblEmployees WHERE ID = " & frmSearch!Searchbox)
I have a drop down box in my classic ASP page and using MS SQL for database. The drop down list includes the brand names starting with lower case, upper case and starting brand name with numbers.
For instance, itcosmetics, Colorpop Cosmetics and 5 Hour energy respectively. Currently, this dropdown is showing/displaying brands alphabetically but by case i.e. lower case, number, upper case.
In other words, it is displaying all lower case brand name alphabetically first then the brand with numbers alphabetically and finally brand names starting with uppercase alphabetically.
However, what I am trying is : I want to display my options according to the alphabetical orders without worrying about the case of the brand name.
for example: if the brand names are 1 apple, applea, Appleb, 3 fans, balla, Ballb, cat, Doll.
Currently, its displaying drop down option as following:
applea
balla
cat
1 apple
3 fans
Appleb
Ballb
Doll
But I want something like following:
1 apple
3 fans
applea
Appleb
balla
Ballb
cat
Doll
How can I do that?
My code :
<select>
<OPTION value=0>-- SELECT --</OPTION>
<%
DIM RS, varQueryBrand, varBrand
IF Request.QueryString("brandID") <> "" THEN
varQueryBrand = Request.QueryString("brandID")
ELSE
varQueryBrand = "SELECT"
End IF
SQL = "SELECT DISTINCT(brand) as brand FROM tblproduct"
SET RS=objConn.Execute(SQL)
IF NOT (RS.BOF and RS.EOF) THEN
WHILE NOT RS.EOF
varBrand = RS("brand")
IF LCase(varQueryBrand) = LCase(varBrand) THEN
Response.Write "<option selected value=""" & replace(RS("brand")," & ","#") & """>" & RS("brand") & "</option>"
ELSE
Response.Write "<option value=""" & replace(RS("brand")," & ","#") & """>" & RS("brand") & "</option>"
End IF
RS.MoveNext
WEND
END IF
RS.close
SET RS = nothing
%>
</select>
I tried writing ORDER BY brand at the end of SQL statement, but there was no chage in the output. So can you please help me?
You are likely using a Collation with the CS designation in it like Latin1_General_CS_AS for example.
To avoid the Unicode Sorting, switch to a Binary Collation to get the expected sort order.
SELECT DISTINCT brand
FROM tblproduct
ORDER BY brand COLLATE Latin1_General_bin
A slightly messier approach is to use a sub query to wrap a lowercase version of the Brand column and use that for sorting.
SELECT x.brand
FROM (
SELECT DISTINCT brand, LOWER(brand) [brand_lower]
FROM tblproduct
) x
ORDER BY x.brand_lower
As #Martha point's out don't forget to specify an ORDER BY in your SQL string in Classic ASP.
Useful Links
ORDER BY … COLLATE in SQL Server
From what it looks like, you aren't currently sorting your results at all, so you're getting whatever default order SQL Server cares to come up with.
Most databases are automatically set to case-insensitive sorting, so unless your database is set up strangely, the following should work:
SQL = "SELECT DISTINCT brand FROM tblproduct ORDER BY brand"
If that doesn't work and you don't feel like messing around with the COLLATION settings, you can sort by an all-lowercase (or all-uppercase) version of the field:
SQL = "SELECT DISTINCT brand FROM tblproduct ORDER BY LOWER(brand)"
I need to keep the original DataTable and filter it based on list values. I've tried to hide rows that don't match up to the list but it doesn't work instantly. I don't want to copy the list to another dataTable and bind my dataGridView to is cause i have too much tied up to the original DataTable. Filtering only works for a few conditions but the list is holds only the values that are needed. Is there a LINQ solution to this? C# only please. This is how I got my list. There is another dataGridView that holds primary key for the datatable that I need to filter. It's key is held in a comboBox.
DataTable MainTable = MainDataSet.Tables["MyTable"];
DataTable lookupTable = lookupDataSet.Tables["MyLookupTable"];
var List = (from x in lookupTable.AsEnumerable()
where x.Field<string>("kAutoInc") == comboBox.SelectedValue.ToString()
select x.Field<int>("Pct")).ToList();
var a = MainTable.AsEnumerable().Where(r =>
List .Any(id => id == r.Field<int>("Pct")));
This gives me values of int 30, 40, 50, 60...
The DataGridView has a matching column "Pct" that I need to filter rows that only contain these values. I know it seems easy but I just can't seem to get it to work.
Please use DataView instead.
dataview dv=new dataview(datatable);
dv.filter=string.format("column1={0}","value1");
Like that.
when I try to insert a value to recordset in the 'Description' field. it showing a error like
runtime error '-2147217887(80040e21)'
Multiple- Step operation generated errors. check each status value.
sql = "SELECT * FROM vePODetail WHERE vePOID=" & Str(ado_veReceive.Recordset("vePOID")) & " ORDER BY vePODetailID"
rs.ActiveConnection = g_cnnCompany
rs.Open sql
Do While Not rs.EOF
ado_veReceiveDetailWF.Recordset.AddNew
ado_veReceiveDetailWF.Recordset("vePODetailID") = rs("vePODetailID")
ado_veReceiveDetailWF.Recordset("prMasterID") = rs("prMasterID")
ado_veReceiveDetailWF.Recordset("Description") = rs("Description")
ado_veReceiveDetailWF.Recordset("QuantityReceived") = rs("QuantityOrdered") -rs("QuantityReceived")
ado_veReceiveDetailWF.Recordset.Update
rs.MoveNext
Loop
rs.Close
the field in the recordset acccepts only 50 char.
Please tell how to increase the size/length of the field in the recordset.
If the field is 50 chars long, you must change the DB's definition of the field from 50 to whatever you need. You cannot do that through a recordset
Assuming you're using SQL Server, you can change your query using a CAST operation:
sql = "SELECT vePODetailID,prMasterID,CAST(Description as VARCHAR(100)) AS Description, QuantityReceived FROM vePODetail WHERE vePOID=" & Str(ado_veReceive.Recordset("vePOID")) & " ORDER BY vePODetailID"
That should set the length of the Description field in the recordset to 100 characters. You can do this in other db platforms as well, but the syntax may be different for the CAST.
Hey guys, just want to ask you a simple question that I know you're familiar with... I am using VB6, I just want to get sets of records from my database. What I mean is that I have UserID and with a part of code provided below, it only gets a single set of record. Like for instance, the value of UserID is A12, and so, all sets of records with the UserID of A12 must display in Textboxes respectively with the aid of datPayroll.Recordset.MoveNext.
With datPayroll
.RecordSource = "select * from tblpayroll where empid like '" & UserID & "'"
.Refresh
Me.txtRegularHours.Text = .Recordset.Fields!reghours
End With
-datPayroll : DataControl
-txtRegularHours : Textbox
-UserID : Variable
You probably want to look at MoveFirst, MoveNext, etc. and also EOF
Here is a link or two to get you started:
EOF, BOF
MoveFirst, MoveNext
You need to check that you have some data in your Recordset using EOF, then MoveFirst to move to the first record, and loop through using MoveNext.