27. oktober 2001 - 12:13Der er
18 kommentarer og 1 løsning
Variabel i DELETE...????
OK jeg er ret Newbie - agtig til det her men jeg spørger alligevel : Hvordan får jeg en variabel med i min SQL sætning : ( fra et c++ prg.. ) .. char *tmpbuf = \"noget\"; query=\"DELETE FROM tabel WHERE column =\'\"tmpbuf\"\'\"; ... Hvorfor virker dette ikke...
Try this: query = \"DELETE FROM table WHERE column =\'A known column\'\"
Replace a known column to a vlue you know exists in the database.
When you write \"DELETE FROM table WHERE column =\'\"tmpbuf\"\' what happnes is th evalue of query gets set to
\"DELETE FROM table WHERE column = \'tmpbuf\'\"
but what are trying to do is get it to look like this
\"DELETE FROM table WHERE column =\'noget\'\"
In VB it would look like this
Dim tmpbuf as string
tmpbuf = \"noget\"
query = \"DELETE FROM table WHERE column =\'\" & tmpbuf & \"\'\"
You can see that tmpbuf is NOT inside the string and this means that the VALUE of tmpbug (noget) get concatonated to the string and not the word \"tmpbuf\" which I think is happening in your case.
Cant you debug your program to see what the contents of query is?
Okay. lad mig lige se, jeg skal altså skrive noget med : ... char *query; string tmpbuf; tmpbuf = \"noget\"; query = \"DELETE... =\'\" & tmpbuf &\"\'\"; .... - Hvilket ikke virker ! : 330: no match for `const char[37] & string &\' :o((
Yes yes.. Jeg har prøvet med \"DELETE...=\'noget\'\"; Og det virker fint...
Prøver med en løkke, der lægger tmpbuf over i query - strengen. noget med :
.... char tmpbuf[] = \"noget\"; char *query; query =\"DELETE FROM notfound WHERE s_word =\"; int tmpbufL = sizeof(tmpbuf); int i = 0; int o = 36; while(i<tmpbufL) { query[o] += tmpbuf[i]; o++; i++; } .... hmmm... virker ikke helt ? help please :o(..
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.