我有一個非常簡單的代碼調用存儲過程。存儲的proc用於發送提醒到用戶的到期賬戶。我的代碼沒有給用戶提供正確的反饋。任何想法如何解決這一問題?
當用戶輸入正確的電子郵件地址,用戶獲得提醒電子郵件消息,「提醒發送成功」
這正是我們想要的東西。
然而,如果用戶輸入無效的電子郵件地址,用戶仍然可以看到同樣的信息,「提醒發送成功」
這是不好的。
你能幫我解決我的問題嗎?
請參閱整個(實際)下面的代碼:
Protected Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles BtnSubmit.Click
Dim oConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("sConnectionString").ConnectionString)
Dim oCommand As SqlCommand = New SqlCommand()
Try
oConnection.Open()
oCommand.Connection = oConnection
oCommand.CommandText = "AcountExpiration"
oCommand.CommandType = CommandType.StoredProcedure
oCommand.Parameters.Add(New SqlParameter("@Email", Data.SqlDbType.VarChar, 50)).Value = Email.Text
Dim adpt As New SqlDataAdapter(oCommand)
Dim ds As New DataSet()
adpt.Fill(ds)
oCommand.ExecuteReader()
lblMsg.Text="Reminder successfully sent"
Catch ex As SqlException
Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('" + ex.Message + "')</SCRIPT>")
Finally
oConnection.Close()
End Try
End Sub
C#的解決方案是值得歡迎的爲好。
Dim scmd As SqlCommand = New SqlCommand("AcountExpiration", Conn)
scmd.CommandType = CommandType.StoredProcedure
scmd.Parameters.AddWithValue("@Email", Email.Text)
'Dim r As SqlDataReader = scmd.ExecuteReader()
Dim validEmail As Boolean = False
Dim reader As SqlDataReader = scmd.ExecuteReader()
While reader.Read()
'if we are here then something got returned.
'so probably a valid email.
validEmail = True
End While
If validEmail = True Then
lblMsg.Text = "Success"
Else
lblMsg.Text = "email does not exit on our system"
End If
你的代碼中的什麼讓你認爲應該顯示錯誤信息?您沒有發佈驗證電子郵件地址的代碼中的任何內容。 –
@Kenny你的存儲過程是什麼樣的?你可能會用'if reader.Read()'離開,因爲你只關心返回的東西。我建議您的存儲過程仍然返回行,無論它是否找到匹配的電子郵件地址... –