Jump to content
Xtreme .Net Talk

Recommended Posts

Guest aXiS_PoWeR
Posted
can anyone tell me an SQL command for adding or deleting a field from SQL Server 2000 using a objCmd.ExecuteNonQuery() ?
Guest aXiS_PoWeR
Posted
lol...i need the table just need to delete or add a column or 2
  • 3 weeks later...
Guest wild wolf
Posted
objCmd.CommandText = "DELETE * FROM myTable WHERE ID > 0"
objCmd.ExecuteNonQuery()

 

hi Derek, i have the following code,

command.CommandText = "DELETE * FROM table WHERE item_id LIKE "+noBox.Text;
command.ExecuteNonQuery();

 

and an exception error is caught saying "Syntax error near '*' "

 

what can the error be?

Posted

Change

 

"DELETE * FROM table WHERE item_id LIKE "+noBox.Text

 

to

 

"DELETE * FROM table WHERE item_id LIKE '" + noBox.Text + "'"

 

You have to put strings inside ' '. If the item_id is supposed to be a number then you'll need to cast noBox.Text to an Integer.

Gamer extraordinaire. Programmer wannabe.
Guest wild wolf
Posted
Change

 

"DELETE * FROM table WHERE item_id LIKE "+noBox.Text

 

to

 

"DELETE * FROM table WHERE item_id LIKE '" + noBox.Text + "'"

 

You have to put strings inside ' '. If the item_id is supposed to be a number then you'll need to cast noBox.Text to an Integer.

 

did not work, still says Syntax error near '*'

 

asrar

Posted
Hmm.. well what exactly is in noBox.Text? Just numbers like 1, 2, 3, etc.. or something like ID1, ID2, ID3, etc..?
Gamer extraordinaire. Programmer wannabe.
Guest wild wolf
Posted
Hmm.. well what exactly is in noBox.Text? Just numbers like 1, 2, 3, etc.. or something like ID1, ID2, ID3, etc..?

 

alphanumeric and the data type for item_id is also alphanumeric.

 

asrar

Guest wild wolf
Posted

hi, the table name is not table but journal_detail, i put table here just to clear things, sorry if i confused anyone.

 

asrar

Guest wild wolf
Posted
sSQL = "DELETE * FROM journal_detail WHERE item_id LIKE '%" & noBox.Text & "%'"

Give it one more shot.

 

hi did not work, the problem is not on how i take the input (i.e it has nothing to do with the noBox.Text), the problem is with the delete command, the error points me towards the * and says the error is before the * in that case its something to do with the delete keyword, and because of that there is a question i would like to ask, can we really use the delete command in this way?

 

asrar

Posted

You know, I haven't done actual SQL code in quite a while so I'm a bit rusty in trying to figure this out.. but I just did a search on http://www.mysql.com (yes I know you're using Access or SQL Server but mysql.com is still a great source to quickly look up generic SQL code) and they have the delete command listed like so;

 

DELETE FROM table WHERE col = 'Stuff'

 

Note the no * at all. Might as well give it a shot, nothing else seems to be working. :eek:

 

Just remember to back up your database before toying with any sort of delete command. ;)

Gamer extraordinaire. Programmer wannabe.
Guest wild wolf
Posted

BINGO wyrd, that did it!!!!! thanx alot :)

 

asrar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...