how to update a record in MYSQL


magdykhfee

Recommended Posts

Posted

I am Using ODBC to link with MYSQL  to make data base for some channels  

it is working fine with me  that i can save any new record or read 

now i want to update (modify) some record in data base 

how to do this in DAQfFactory ?

 

Posted

Use db.execute() and specify your UPDATE sql command.  With db.execute() you can pretty much run any sql command you want, except maybe SELECT, and for that one you use db.queryToClass()

 

Posted

-first problem :

please give me example how to use db.execute() , i is always giving error 

i can do this using mysql,  

select* from table1;
update table1 
set NAME = 'xyz' 
where ID=60 ;

how i can do in daqfactory 

 

 

- second problem :

when i try to search about id =60 i table it working fine  

qr = db.Query(dbase,"select * from table1 where ID = '60'")

the problem when i replace this with normal variable it is not working 

qr = db.Query(dbase,"select * from table1 where ID = var10")

how to write this using variable 

please give me the refrence that explain  db.execute()

i cant find in normal help 

 

thanks 

Posted

private dbase = db.open("mydatasource")
private result = db.queryToClass(dbase, "select * from table1;")
db.execute(dbase, "update table1 set NAME = 'xyz' where ID=60")

As to your second problem, the ODBC database doesn't know anything about the internal variables of DAQFactory.  It gets the string that you provide in execute() or query().  So, you need to make create the string out of the variable:

qr  = db.query(dbase, "select * from table1 where ID = " + var10)

Also, I recommend using queryToClass() instead of query() for just about everything.  It is much faster and easier to use.
 

Archived

This topic is now archived and is closed to further replies.