Sqlce drop table

  • Thread starter Thread starter Pablo Nogues
  • Start date Start date
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.
 
Hi Christian, i wan´t to drop the table, y need only delete it.

Any idea ?

thanks!
 
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
 
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
 
Yes, you are right Alberto.

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

Any idea ?

thanks
 
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
 
Back
Top