Go4Expert

Go4Expert (http://www.go4expert.com/)
-   SQL Server (http://www.go4expert.com/forums/sql-server-forum/)
-   -   vb.net and sql server(delete cmd) (http://www.go4expert.com/forums/vbnet-sql-server-delete-cmd-t20930/)

rockyy 10Feb2010 16:07

vb.net and sql server(delete cmd)
 
1 Attachment(s)
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


sql-programs 19Jul2013 13:37

Re: vb.net and sql server(delete cmd)
 
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


All times are GMT +5.5. The time now is 18:59.