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
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