2012-09-20 62 views
0

進口System.Data 進口System.Data.Odbc我想要顯示成功插入數據到數據庫後的客戶端消息..所以如何實現這個使用alert()消息在JavaScript?

分部類ADD_Employee 繼承System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Dim cons, query As String 
    Dim con As OdbcConnection 
    Dim cmd As OdbcCommand 
    cons = "dsn=Courier; UID=Courier; PWD=123;" 
    con = New OdbcConnection(cons) 
    con.Open() 
    If (RadioButton1.Checked) Then 
     query = "insert into EMPLOYEE values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & "Male" & "','" & TextBox6.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')" 
     cmd = New OdbcCommand(query, con) 
     cmd.ExecuteNonQuery() 

    End If 
    If (RadioButton2.Checked) Then 
     query = "insert into EMPLOYEE values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & "Female" & "','" & TextBox6.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')" 
     cmd = New OdbcCommand(query, con) 
     cmd.ExecuteNonQuery() 
    End If 


    con.Close() 
End Sub 

末級

回答

0

,你可以嘗試這樣的事情

me.ClientScript.RegisterStartupScript(me.GetType(), "message", "alert('records has been inserted to the database!');", True) 
+0

非常感謝......它鍋... –

+0

@PramodLokare歡迎您考慮採取它作爲答案! –

0
me.ClientScript.RegisterClientScriptBlock(Me.[GetType](),"Data Added","alert('Success!');") 
0

RegisterStartupScript如前面的答案中所述是執行此操作的方法。

但是,您確定要使用警報嗎?在用戶體驗方面不建議。你應該看看一些網站,看看它是如何完成的。例如,一旦我發佈了這個答案(我想它被添加到某個數據庫),我不會得到警報,而是一個更微妙的信息。因此,我建議擁有一些「成功」標籤,並將其Visible屬性更改爲true,或者可以使用Response.Redirect並將用戶重定向到整個成功頁面,這完全取決於您希望給用戶的體驗。

+0

好的...謝謝你的建議..... –

相關問題