Delete in mssql via Datagrid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Nibor
Posts: 18
Joined: Wed Nov 21, 2012 12:13 pm
Location: Germany

Delete in mssql via Datagrid

Post by Nibor » Fri Dec 07, 2012 12:36 pm

Hey guys,

I've a problem with deleting data from my mssql database viá a datagrid.
I want to delete the hilitedline of my datagrid and refresh the view. So that I
can see the updated version of it.
This is my code but it doesn't work maybe someone can help me
finding the mistake I made.
___________________________________________________________________________________________
global gDB
on mouseUp
answer warning "Are you sure that you want to delete this data?" with "No" or "Yes"
if it is "No" then
exit to top
end if
set the itemDelimiter to tab
put the dghilitedlines of group "dg1" into tNum
if tNum is "" then exit mouseUp
put the dgDataOfLine[tNum] of group "dg1" into theDataA
put theDataA["UserID"] into tUserID
put "DELETE FROM [xxxx].[xxxx].[xxxxx] WHERE UserID='" & tUserID into vSQL
put revdb_execute(gDB,vSQL) into vTmp
answer information "Successfully deleted."

put "SELECT xxxx,xxxx,xxxx,xxxx,xxxxx,xxxxx,xxxxx,xxxx FROM [xxxxx].[xxxx].[xxxxx]" into vSQL
put revDataFromQuery(Tab,Return,gDB,vSQL) into tRS
set the dgtext of group "dg1" to tRS
end mouseUp
___________________________________________________________________________________________

regards

Nibor

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Delete in mssql via Datagrid

Post by Klaus » Fri Dec 07, 2012 1:39 pm

Hi Nibor,

well, I am sure you understand that "doesn't work" is not the best error description! 8)
What exactly does not work? Do the db entries not get deleted?
Do you get an "revdberror" or any other error?

At first glance I see that your "delete" string is missing a final ' (single quote)!
...
## Should read:
put "DELETE FROM [xxxx].[xxxx].[xxxxx] WHERE UserID='" & tUserID & "'" into vSQL
...
Maybe this will fix your problem already!?

And get used to error checking, which is essential and may save your life from time to time! :)

Hint:
Do also delete the lines in your datagrid, so you do not need to need to fill the datagrid
again with the updated data from the database! 8)
...
## Add this instead of your last db query:
dispatch "deletelines" to grp "dg1" with tNum
...


Best

Klaus

Nibor
Posts: 18
Joined: Wed Nov 21, 2012 12:13 pm
Location: Germany

Re: Delete in mssql via Datagrid

Post by Nibor » Fri Dec 07, 2012 1:55 pm

Hey,
about the "doesn't work" sorry. I was talkin 'bout that it doesn't delete the entry
in my database or the datagrid.

Thank you very much =)
now everything is fine with the delete button.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Delete in mssql via Datagrid

Post by Klaus » Fri Dec 07, 2012 2:13 pm

Ah, great, so it was in fact the missing single quote?

Hint: Check the results of your SQL queries to see if and what might be wrong:
...
put "DELETE FROM [xxxx].[xxxx].[xxxxx] WHERE UserID='" & tUserID into vSQL
put revdb_execute(gDB,vSQL) into vTmp
if vTmp begins with "revbderr" then
## something went wrong!
answer vTmp
## or whatever...
...

Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”