Not Deleting Entry if Column is Varchar

rockyy

Active member
Joined
Feb 3, 2010
Messages
25
Programming Experience
Beginner
there is a big problem

my database contains three columns
id-varchar(bcuz my entery contains / and in int its not possible)
name-varchar
bookname-varchar

i m adding and deleting by Stored Procedure

there is no problem while adding but problem comes while deleting the record
suppose my enteries are
1/2
1/3
21

its not deleting 1/2 and 1/3 as they contains (slash)

see delete code
VB.NET:
Expand Collapse Copy
 Try
            con.Open()
            flag_author = check_data("select author_id from authorlib where author_id= " & TextBox1.Text & " ", con)
            If flag_author Then
                cmd = New SqlCommand("deleteauthor", con)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@author_id", TextBox1.Text)
                cmd.ExecuteNonQuery()

                MessageBox.Show("record delete")

                flag_author = False
            Else
                MessageBox.Show("This author Number Do not Exist", "Stop", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error)
            End If

            con.Close()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            con.Close()


        End Try

pic for more info

Showing Error even entry exist
v3kdjn.jpg


Sql Entry
xdbg2p.jpg


any sol. i want to delete the entry from frontend only
 
In the form you have 1/2 entered in the text box.

Your code is
VB.NET:
Expand Collapse Copy
select author_id from authorlib where author_id= " & TextBox1.Text & " "

This gets translated into
VB.NET:
Expand Collapse Copy
SELECT Author_ID FROM AuthorLib WHERE Author_ID = 1/2

SQL sees 1/2 as a mathematical expression rather than a varchar. Either add single quotations around TextBox1.Text or make the SQL statement parameterized. I would strongly suggest making all SQL statements parameterized. This will prevent this in the the future and it will also prevent any errors if you entered a single quotation in TextBox1.Text.
 
can u give the link where i can start to learn sql parameterized query as i also want to insert delete and update values through textbox
any good link of example will be great help
 
Back
Top