How to change values of a mysql database via dbgrid? - mysql

Hey guys good morning,
i got a DBGrid and the UniDac components. I a use a popupmenu and select a row. I fill via the onclick event from the popupmenu a new form with my data in my TEdit.
Now the problem is, that i want to edit my data which i selected from the dbgrid.
This code works until dbgrid is refreshed and then the old values are back again in my dbgrid. How can i change it for the mysql table too not only for the dbgrid?
My actually Code:
FQuery.Edit;
FQuery.FieldByName('CfgUID').AsString := Edit4.Text;
FQuery.FieldByName('CfgMod').AsString := Edit1.Text;
FQuery.Post;

The solution was to disable CachedUpdates or call ApplyUpdates after Post.

Related

How do I create a Microsoft's Access field within Delphi using code

I am currently working on a Bed and Breakfast management system. I want to create a Microsoft access field in Delphi using code. The field name I want to create is rooms, I want the data type to be text and I want the size to be 6. I found some code on a stack overflow post but not everything. I dont know what to put in the brackets.
//Adds the field to the ms access database
Adotable2.fielddefs.add()
It is quite simple to add a field to an Access table, provided no app has the table open at the time. However, using FieldDefs.Add is not the way to do it, because it does something else which isn't relevant to this task.
Assuming your Delphi form (or datamodule) has an AdoTable1 set up to access the table you want to alter, and that the table's name in the Access database is 'Hotels', this will add the Rooms column to it:
procedure TForm1.Button1Click(Sender: TObject);
begin
if AdoTable1.Active then // close the Hotels table if AdoTable1 accesses it
AdoTable1.Close;
try
AdoConnection1.Connected := True;
AdoConnection1.Execute('alter table Hotels add column rooms text(6)');
finally
AdoTable1.Open;
end;
end;
Note: My AdoConnection1 is set up to access the database using the 'Microsoft Office 16 Access Database Engine OLE DB Provider'.
Btw, if you use "persistent fields" in your AdoTable (the list of fields you get if you right-click on it and select 'Fields Editor ...' from the pop-up menu, you will need to add the Rooms field to it. If you don't use persistent fields, you don't need to worry about this.
The FieldDefs.Add you mentioned is for adding a field in your Delphi app to e.g. AdoTable1 if, for some reason, it did not already include it, for example if you added the field to the table using the MS Access app.

ora-01403 at run time environment Only [duplicate]

This question already has an answer here:
enable-update-delete-insert a row when radio buttons pressed
(1 answer)
Closed 7 years ago.
after i had alert one of my tables column and change its type from
number to varchar2 and changing the data type also for the text item
I tried also the data block wizard to refresh the data block and also
write the DISPLAY_ERROR at each step but nothing show up !
I had tried to delete the FMX file and recompile the form and generate the FMx file but thats was not help !!
frm-40508 oracle error unable to insert record !
at run time environment Only but when I run the from from developers
it is works fine !
i know it should be sample error to solve but all my tried had fail
whats the problem please !
is their any cache or something I need to refresh it ?!
should I delete the whole datablock and re-builded cause of that little change ?!
Just for sharing my problem that I was navigating through multiple forms using
OPEN_FORMS which is by default has NO_SHARE_DATA_LIBRARY I had replace it with
CALL_FORM which is has same parameters as OPEN_FORMS but it is allow forms to do update insert and delete transactions for more understanding Please refer to oracle forms builder help search for OPEN_FORM AND CALL_FORM key words
Thanks

MySQL result to array VB.NET

I am creating a program in VB.NET which uses an online MySQL database to retrieve certain data. I have now succeeded in connecting and getting some basic stuff out of it. Now, what I want to do is that when an user presses a button it has to update the list. What happens is that the stuff that is already in the database also gets resent and so the list just doubles himself, although it adds the new database value.
How can I make sure that it only adds new values to the list, instead of adding all values from the list again? I have read that you can use the Preserve keyword with arrays, though this isn't an array and neither have I figured out how to convert my data into an array.
Private Sub generateList()
DB.writeQuery("SELECT snacks.ID, snacks.naam, snacks.baktijd FROM snacks")
While DB.DR.Read
ListBox1.Items.Add(DB.DR.Item("naam"))
End While
DB.closeConnection()
End Sub
This is the piece of code I use to generate the list, I reuse this code to refresh the list. As you can see, it uses my own written MySQL class. I know it makes an connection so there is nothing wrong with that.
Any help would be appreciated.
What you will want to do is to clear the ListBox before you reload the list. You can do this like so:
ListBox1.Items.Clear()
Then when you reload the list, the items will not be duplicated.
Looks like you need to clear your listbox before adding the items.
ListBox1.Items.Clear()
Try this my friend:
If Not listBox1.Items.Contains(DB.DR.Item("naam")) Then
ListBox1.Items.Add(DB.DR.Item("naam"))
else
'this item already exists.
end if

Lazarus, can't get DB Update working. How can I preview whats being submitted?

Hi I have a form setup using TMySQL51Connection, TSQLTransaction & TSQLQuery modules, it retrieves info from the DB without issue but I'm having problems with updates.
The DB is pretty large so I'm starting with just the 1st couple of rows, once they're working I'll extend the query.
My TSQLQuery.UpdateSQL is as follows
UPDATE table SET
ContactFirst = :ContactFirst,
ContactSur = :ContactSur
WHERE AccountID = :AccountID
Then I have a button in my form, the onCLick event contains:
begin
accSelect.Edit;
accSelect.Post;
accSelect.ApplyUpdates;
dbTransaction.CommitRetaining;
sqlbl1.Caption := accSelect.UpdateSQL;
end;
Clicking the buttons does precisely nothing with the DB, it generates no error messages, just updates the caption on sqlbl1. Is there anyway to preview what Lazarus is sending to the DB with values included so I can track down whats going wrong?
I tried adding a logging event to the SQLConnection but couldn't work out how to get it generating logs.
From my experience, the Edit, Post and ApplyUpdates methods are used in conjunction with a TClientDataSet. In that case you would simply assign new values to the fields in the CDS (after navigating to the record you want to Edit) then Post those changes (no need for an Update SQL statement). Something like this...
MyCDS.Edit;
MyCDS.FieldByName('ContactFirst').Value := sContactFirstName;
MyCDS.FieldByName('ContactSur').Value := sContactSurname;
MyCDS.Post;
MyCDS.ApplyUpdates;
Alternatively, you could use a Query component, write the UPDATE SQL into the SQL property, and use ExecSQL or whatever method has been implemented for that component (there are many database access components that each have their own idiosyncrasies)
Here's some code off the top of my head. Please excuse me but I'm not familiar with Lazarus specifics - it's basically Delphi code.
MySQLQuery.SQL.Clear;
MySQLQuery.SQL := 'UPDATE MyTable
SET ContactFirst = :ContactFirst,
ContactSur = :ContactSur
WHERE AccountID = :AccountID';
MySQLQuery.Params.ParamByName('ContactFirst').Value := sContactFirstName;
MySQLQuery.Params.ParamByName('ContactSur').Value := sContactSurname;
MySQLQuery.Params.ParamByName('AccountID').Value := iAccountID;
try
MySQLQuery.ExecSQL;
ShowMessage('Update succeeded');
except on e: Exception do
ShowMessage(e.Message);
end;
So it might be that you've ended up using half of both methods and neither of them completely.

NotInList script

I am trying to use Access and VBA to create a DB to store my library. I already posted a question and got a useful answer but I am still failing with the basics, so, after having checked this tutorial link I am starting from scratch and doing it in smaller steps (i.e. asking more basic questions...).
I have the following DB structure and relationship details:
DB structure and relationship details http://img195.imageshack.us/img195/8184/relationshipdetails.png
Using the Access AutoForm:Columnar wizard I created a Form based on the Table Libri, then I changed the field "Stanza" into a ComboBox, I entered the RowSource as follows:
ComboBox http://img560.imageshack.us/img560/160/comboboxdata.png
Then in the Event tab I selected the ... controls in the NotInList and in the VBA I entered the following code:
VBA code http://img689.imageshack.us/img689/1416/notinlistcode.png
Saved everithing, but when I open the Form Libri and try to enter a value in the ComboBox I get the following error message:
Error message http://img41.imageshack.us/img41/8937/errormsgt.png
All my tables are empty (no records).
So the VBA code seems not to be considered/executed at all, what am I doing wrong or missing?
Ok, I was completely blind.
The error is the option: "Limit to list" that I set to "NO" and instead, the NotInList event is only filred if such option is set to "yes".
I find this conter-intuitive, but at least now I know.
Sorry for bothering other. hope this is helpful some other newbe like me.