2016-08-22 83 views
1

我有一個註冊和登錄系統,我需要從SQL數據庫調用名稱變量。我需要一個歡迎信息。如何從SQL數據庫「調用」值?

label2.Text = "Welcome!" + nameFromDatabase; 

如何從數據庫中檢索名稱值?

+0

發佈您的嘗試代碼 –

+0

我們不會給你所有的書面代碼。嘗試從[這裏](http://stackoverflow.com/questions/27043733/welcome-message-on-master-page-after-login)如果你卡住任何地方,然後張貼問題 – BNN

+0

我只需要一個代碼是什麼從sql數據庫中調用標籤消息的值 – CoopCky

回答

0

如果您在網站上使用ASP.NET membership,則可以顯示當前用戶username在用戶登錄,請參閱下面的代碼: - 。

protected void Page_Load(object sender, EventArgs e) 
{ 
    // First find if user is logged in 
    if (Context.User.Identity.IsAuthenticated) 
    { 
     // Finds user name and says Welcome 
     lblWelcome.Text = "Welcome " + Context.User.Identity.Name; 
    } 
    else 
    { 
     // It is anonymous user, say Welcome to guest 
     lblWelcome.Text = "Welcome guest"; 
    } 
} 

另一種方式是把用戶名在Session和通過使用標籤顯示它

lblWelcome.Text = "Welcome " + Session["UserName"].ToString(); 
+0

非常感謝你,我做到了:) – CoopCky

+0

如果這能爲你工作,請打勾並接受它作爲答案。這將有助於未來的讀者。謝謝。 – BNN