Sqlce drop table

P

Pablo Nogues

Hi, i´ve a method that expects a string parameter (table name to drop ) in
CF 3.5 C#, that returns error. My code is:


...........//

cmd.CommandText = "Delete @Table" ;

cmd.CommandType = System.Data.CommandType.Text;

cmd.Parameters.AddWithValue("@Table", table);

-------------//

My cuestion is why i can´t call in this way ?

Thanks in advanced.
 
P

Pablo Nogues

Hi Christian, i wan´t to drop the table, y need only delete it.

Any idea ?

thanks!
 
G

Guest

Pablo Nogues pisze:
Hi Christian, i wan´t to drop the table, y need only delete it.

So what is the difference between drop and delete the table?

If you want REMOVE TABLE from the database use
drop table name

but if you want REMOVE DATA FROM THE TABLE use

delete from name
 
A

Alberto Silva, MVP

The problem may be with replacing the object system name with a parameter.
If you embed the table name in the DELETE command, it works as expected,
right?

Alberto Silva

Pablo Nogues said:
Hi, i´ve a method that expects a string parameter (table name to drop ) in
CF 3.5 C#, that returns error. My code is:


..........//

cmd.CommandText = "Delete @Table" ;

cmd.CommandType = System.Data.CommandType.Text;

cmd.Parameters.AddWithValue("@Table", table);

-------------//

My cuestion is why i can´t call in this way ?

Thanks in advanced.



__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4600 (20091112) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4611 (20091116) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
P

Pablo Nogues

Yes, you are right Alberto.

The problems is when is user a command parameter with the name of my table.

Any idea ?

thanks
 
A

Alberto Silva, MVP

Hola Pablo,
Why don't you just 'concatenate' the table name to the "DELETE FROM "
command? Or if you prefer, keep the "DELETE FROM @table" command string, but
when executing, replace yourself with string manipulation functions,
"@table" with the table name.

Alberto Silva

Pablo Nogues said:
Yes, you are right Alberto.

The problems is when is user a command parameter with the name of my
table.

Any idea ?

thanks






__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4616 (20091117) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4616 (20091117) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top