When i try to search both column, there is no filter. i want to list 5 and 30.05.2016 in dbgrid.
adoquery1.Close;
adoquery1.SQL.CLEAR;
adoquery1.SQL.Add('select * FROM Sheet11 ');
adoquery1.SQL.Add('where field9 like :blm and field12 like :blm1');
adoquery1.Parameters.ParamByName('blm').Value:='5';
adoquery1.Parameters.ParamByName('blm1').Value:='30.05.2016';
adoquery1.Open;
So what is exactly the question there ?
Using parameters is right, one better not use string splicing due to all kinds of fragility and unexpected side effects - http://bobby-tables.com
And use proper data types!
adoquery1.SQL.Text := 'select * FROM Sheet11 ' +
'where ( field9 = :_p_field9 ) ' +
' and ( field12 = :_p_field12 )';
with adoquery1.Parameters do begin
ParamByName('_p_field9').AsInteger := 5;
ParamByName('_p_field12').AsDateTime := EncodeDate( 2016, 05, 30 );
end;
adoquery1.Open;
You've got a pretty bad SQL error. LIKE does not work for any types other than strings (CHAR, VARCHAR, etc.). It does not work for numbers or dates. You're looking for = instead, for exact matches, or BETWEEN if you want something between two values.
This should work for you:
adoquery1.Close;
adoquery1.SQL.CLEAR;
adoquery1.SQL.Add('select * FROM Sheet11 ');
adoquery1.SQL.Add('where field9 = :blm and field12 = :blm1');
adoquery1.Parameters.ParamByName('blm').Value:= 5; // Notice no quotes
adoquery1.Parameters.ParamByName('blm1').Value:= '2016-05-30'; // Note no extra quotes
adoquery1.Open;
Related
I hope someone can me help again, regarding to my solved stored procedure problem
Is there any chance to make the operator ">" flexible?
Right now my stored procedure works very fine and I will get an eMail when the record count is bigger than the param Menge.
The code is this:
#Menge as int = 0,
#recordCount as int = 0,
set #MySQL = 'select #recordCount=count(2) from ' + #MyTable + ' where ' + #MyWhere
exec sp_execute #MySQL, N'#recordCount int OUTPUT', #recordCount=#recordCount OUTPUT
IF #recordCount > #Menge
begin
...
EXEC msdb.dbo.sp_send_dbmail
Now I want to make > flexible to get an e-mail when the record count is smaller than menge
I tried to declare the param but I don't know how to insert it into the if #recordcount > #Menge line :(
#OpInd as char(1) = null
I would call the stored procedure with
exec sp_eMail_Test3
#Menge = 0,
#eMail_TO = 'testuser#test.xx' ,
#eMail_Subject = 'test3 ',
#eMail_Body = 'Hallo, das ist ein Test',
#MyTable ='test' ,
#MyWhere = 'not [sys_completed] is null'
#OpInd = '<'
If I try IF #recordCount + #OpInd + #Menge then I get the error
An expression of non-boolean type specified in a context where a condition is expected, near 'begin'.
Hopefully you understand my Target and can help me.
If necessary I need to build a 2nd stored procedure :( one for "<" and one for ">"
Best regards Ralf
Just change your operand to <>
IF #recordCount <> #Menge
begin
...
EXEC msdb.dbo.sp_send_dbmail
There are only 3 possible operands you want to deal with. >, <, and =. Since you want an email if it's > or if it's < then just send the email when it's not =.
Another way would to repeat your code.
IF (#recordCount > #Menge or #recordCount < #Menge)
begin
...
EXEC msdb.dbo.sp_send_dbmail
If you are trying to make it either > or < then you can use DynamicSQL. Something like...
declare #sql varchar(max)
set #sql =
'IF ' + cast(#recordCount as varchar(16)) + ' ' + #OpInd + ' ' + cast(#Menge as varchar(16)) + '
begin
...
EXEC msdb.dbo.sp_send_dbmail'
EXEC(#sql)
Im having a form with 2 buttons with 2 different events one sets an order to be ready the other to be declined. For my stringgrid i select records from database, and for the buttonClick events i create UPDATE query, with the advStringGrid.Selectedtext which value i put in the UPDATE query. But the problem is when i first click Ready button and after that i click Decline button,without closing form, then the string value remains only until first click. Perhaps theres an option to "immediately" or w/o closing form to get new value for advStringGrid.Selectedtext variable.
procedure TfTodoList.setRefusedbtnClick(Sender: TObject);
var
i: Integer;
begin
if (Sender = setRefusedbtn) and (State = 0) then
begin
qryExec.Sql.Text := 'Update KitchenOrderRow Set StatusID = 1' +
' Where (OrderId in (Select OrderId from KitchenOrderHeader ' +
' Where Invoice = ' + IntToStr(Orders[X].Invoice) +
')) and (InvRowId = ' + IntToStr(Orders[X].InvRowId) + ')';
advOrderGridClickCell(Sender, X, Y);
end
else if (State = 1) and (setRefusedbtn = Sender) then
begin
ProductName := advOrderGrid.SelectedText;
qryExec.Sql.Text := 'Update KitchenOrderRow Set StatusID = 1' +
' where productName = ''' + ProductName + ''' and StatusID = ' +
IntToStr(qryStatusStatusID.asInteger) + '';
State := 0;
// fk_lib.logisse(nil, qryExec.Sql.Text);
end;
qryExec.ExecSQL;
advOrderGrid.RemoveSelectedRows;
end;
If you update some values in dataset which are used in DbGrid, you should refresh the dataset connected to DbCrid. Close/Open form do this.
After execution of update query do this :
Grid.Datasorce.DataSet.Refresh;
or
Grid.Datasorce.DataSet.Close;
Grid.Datasorce.DataSet.Open;
Update:
If your grid is not connected directly with database through datalink(datasource) you can refresh it as execute the same procedure which is used to fill the grid with data.
I have a string that contains 8 to 12 characters (alphanumeric). I would like to use the Format function to format it such that after first 4 characters a hyphen to be inserted and after next 3 characters another hyphen to be inserted:
cccc-ccc-c
if string has 8 chrs
cccc-ccc-cc
if string has 9 chrs
cccc-ccc-ccc
if string has 10 chrs
cccc-ccc-cccc
if string has 11 chrs
cccc-ccc-ccccc
if string has 12 chrs
Is it possible to use a single lined Format function to acquire the effect? I admit that the usage of Format function is beyond my grasp.
The function you are looking for is FormatMaskText located in System.MaskUtils. The Mask to be used is 'cccc-ccc-ccccc;0;'.
Use Insert instead of Format:
Insert(s, '-', 5);
Insert(s, '-', 9);
There is no built-in format specifier (or combination of them) that will do the formatting you're looking to do.
You can, of course, write your own function to do so (name it, of course, with something meaningful to the values you're formatting):
function MyFormat(Value: string): String;
begin
Assert(Length(Value) >= 8);
Result := System.Insert(Value, '-', 5);
Result := System.Insert(Result,'-', 9);
end;
Use it:
Value := MyFormat('12345678'); // Returns '1234-567-8'
Value := MyFormat('123456789'); // Returns '1234-567-89'
Value := MyFormat('1234567890'); // Returns '1234-567-890'
If you insist on trying to do it with Format, you need multiple calls to Copy (although you can skip the first one by using a width specifier). These can be done, of course, on a single line; I've spread it across multiple just for formatting here to eliminate horizontal scrolling.
Str := '12345678';
Value := Format('%.4s-%s-%s',
[Str,
Copy(Str, 5, 3),
Copy(Str, 8, MaxInt)]); // Return '1234-567-8'
Str := '1234567890';
Value := Format('%.4s-%s-%s',
[Str,
Copy(Str, 5, 3),
Copy(Str, 8, MaxInt)]); // Return '1234-567-890'
There is no way to use a "width specifer" type method to extract substrings within a string, though. (You can extract the first n characters using %.ns, but you can't do the first n characters starting at the fourth with any combination of specifiers.)
I wrote this query:
Ado_All.Parameters.Clear;
Ado_All.SQL.Clear;
Ado_All.SQL.Add('update Tbl_Customer_Services set fk_Customer =:0, fk_Services =:1, Start_Date =:2, End_Date=:3');
Ado_All.SQL.Add(' ,Hesab =:4, Domain_Name =:5,Comments =:7 where Customer_Services_Id =:6 ');
Ado_CmbNames.MoveBy(Cmb_Customer.ItemIndex);
Ado_All.Parameters[0].Value := Ado_CmbNames.FieldByName('Customer_Id').AsString;
Ado_All.Parameters[1].Value := '1';
Ado_All.Parameters[2].Value := '10/10/2010';
Ado_All.Parameters[3].Value := '10/10/2010';
Ado_All.Parameters[4].Value :=Txt_Mali.Text;
Ado_All.Parameters[5].Value := Txt_Domin.Text;
Ado_All.Parameters[6].Value := ADOQuery2.FieldByName('Customer_Services_Id').AsString;
Ado_All.Parameters[7].Value := Txt_Domin.Text;
Ado_All.ExecSQL;
Ado_All is an AdoQuery. but it has following error:
Any idea?
I suspect that the colon characters (:) in the SQL statement are causing the problem. Try simply using = ? as the placeholders for the parameter values in the SQL text, e.g.
UPDATE Tbl_Customer_services SET fk_Customer = ?, fk_Services = ?, ...
and be sure to add the parameter values to the .Parameters collection in the exact order that they appear in the SQL statement.
I am using insertion sort to sort a stringlist (EmailingListArray below).
EmailingListArray[1] is an array that contains names.
EmailingListArray[2] contains corresponding emails.
I am sorting EmailingListArray[1] and when something changes within it, it also changes the second array, so they are sorted together.
An awkward way of doing things, I know, but it's for coursework and I wanted to put an insertion sort in somewhere to try get an extra mark :L
Here's my code
//quick check to make sure array contains correct values
for first := 0 to EmailingListArray[1].Count do
ShowMessage(EmailingListArray[1][first]);
//then sort
First := 0;
Last := EmailingListArray[1].Count;
for CurrentPointer := First +1 to Last-1 do
begin
CurrentValue := EmailingListArray[1][CurrentPointer];
CurrentValue2 := EmailingListArray[2][CurrentPointer];
Pointer := CurrentPointer + 1;
while ((EmailingListArray[1][Pointer] > CurrentValue) AND (Pointer > 0)) do
begin
EmailingListArray[1][Pointer+1] := EmailingListArray[1][Pointer];
EmailingListArray[2][Pointer+1] := EmailingListArray[2][Pointer];
pointer := Pointer -1;
end;
EmailingListArray[1][Pointer + 1] := CurrentValue;
EmailingListArray[2][Pointer + 1] := CurrentValue;
end;
//show message at the end for a check
ShowMessage('hello?');
The message "hello?" isn't being displayed for some reason :S.
The program isn't crashing or anything so it really should atleast display "hello?" at the end.
It isn't sorting my arrays either.
Neither am I sure if the algorithm is written correctly, I got it out of our textbook.
Any help would be much appreciated!
If you want to get a good mark:
Avoid giving misleading names for your variables:
CurrentPointer should be called CurrentIndex or CurrentPosition as it is an index and not a Pointer
Pointer is to be avoided (reserved for Pointer type) and more so because it is not a Pointer; should be WorkIndex or WorkPosition
Read the Insertion sort algorithm (wikipedia has a simple pseudocode for array indexed from 0) and implement it properly:
WorkIndex := CurrentIndex - 1; // - not + in your "Pointer := CurrentPointer + 1;"
Get your Index range from 0 to Count-1 for a TStrings.
Don't mix up the 2 arrays:
EmailingListArray[2][WorkIndex + 1] := CurrentValue2; // not CurrentValue
Update: Missed the bad while condition for zero based array.
2bis. While condition should be with >=0, not >0
while ((EmailingListArray[1][WorkIndex] > CurrentValue) AND (WorkIndex >= 0)) do