vb.net and sql server(delete cmd)

rockyy's Avatar, Join Date: Feb 2010
Newbie Member
can anyone tell me the right way


its showing the msg even when the author id doesn't exist

i want it sshould delete only those id's which are present in the database
else it shld give msg no recorsd found

my code please correct me: )
Code:
If TextBox2.Text <> "" Then

            connectionString = "Data Source=hello\SQLEXPRESS;Initial Catalog=mytanveer;Integrated Security=True"

            SQLStr = "DELETE FROM author WHERE author='" & TextBox1.Text & "'"

            'Write to SQL

            SQLConn.ConnectionString = connectionString             SQLConn.Open() 

            SQLCmd.Connection = SQLConn 
            SQLCmd.CommandText = SQLStr 
            SQLCmd.ExecuteNonQuery() 

            SQLConn.Close()   
            MsgBox("author data deleted", MsgBoxStyle.OkOnly)
        Else

            MsgBox("Enter the required values:" & vbNewLine & "1. Au_ID")

        End If


    End Sub
Attached Images
File Type: jpg Untitled.jpg (27.4 KB, 4 views)
0
sql-programs's Avatar, Join Date: Oct 2009
Go4Expert Member
If TextBox2.Text <> "" Then
int authorId=Convert.Toint32(TextBox2.Text.ToString())

connectionString = "Data Source=hello\SQLEXPRESS;Initial Catalog=mytanveer;Integrated Security=True"

SQLStr = "DELETE FROM author WHERE author=" & authorId

'Write to SQL

SQLConn.ConnectionString = connectionString
SQLConn.Open()
SQLCmd.Connection = SQLConn
SQLCmd.CommandText = SQLStr
SQLCmd.ExecuteNonQuery()

SQLConn.Close()
MsgBox("author data deleted", MsgBoxStyle.OkOnly)
Else

MsgBox("Enter the required values:" & vbNewLine & "1. Au_ID")

End If


End Sub


Please Check it