Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i create small vb.net project. when i delete
record by name display erro message like
this "
system.data.sqlclient.sqlexception:invalid
column name 'jak'. at system .data.........

but actualy 'jak' and his infomation saved
in table. then i try delete his infomation by
his age. its worked. but i have no idea
delete infomation by names. my code is
VB
try
Dim del As new sqlcomand("DELETE FROM
members WHERE name="& textbox1.text
& "", dbcon)
dbconn.open()
del.execuenonquery()
dbconn.close()
Catch ex as Exception
Msgbox(ex.tostring)
end try

is it corect??
please friends help me. I'm using vb.net
and sql server. table name is members. there have two fields. its name(text) and age(int)
thank you.
Posted
Updated 3-Feb-12 10:45am
v2
Comments
palraj001 3-Feb-12 5:07am    
repace this
Dim del As new sqlcomand("DELETE FROM
members WHERE name='"& textbox1.text
& "'", dbcon)

Firstly, you shouldn't do it like that - it is an invitation to an SQL Injection attack, which can damage or destroy your database. Use Parametrized queries instead:
VB
Dim del As new SqlCommand("DELETE FROM members WHERE name=@NM", dbcon)
del.Parameters.AddWithValue("@NM", textbox1.Text)


Secondly, you may find your problem disappears as well!
 
Share this answer
 
Comments
Amal anjula 3-Feb-12 5:20am    
thanks u lot! lot
Jaganathan Bantheswaran 3-Feb-12 6:07am    
My 5up
Code is correct but at the time of coding and database table creation abide Naming on the name of Keywords.
 
Share this answer
 
Try this
VB
Dim del As new SqlCommand("DELETE FROM members WHERE name=@NM", dbcon)
del.Parameters.AddWithValue("@NM", textbox1.Text)

or

VB
Dim del As new sqlcomand("DELETE FROM
members WHERE name='"& textbox1.text
& "'", dbcon)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900