在後面的代碼,我有這樣的:asp.net獲取當前用戶ID
protected void ButtonSave_Click(object sender, EventArgs e)
{
Guid guid = (Guid)Membership.GetUser().ProviderUserKey;
string name = TextBoxCategoryName.Text;
// string user = Membership.GetUser().UserName;
this.connection.Open();
command = connection.CreateCommand();
command.CommandText = "insert into ProfitCategories(name, IdUser) values ('" + name + "', "+guid+")";
command.ExecuteNonQuery();
connection.Close();
}
但這給錯誤:Incorrect syntax near 'a8'.
如何從當前用戶獲得GUID,並插入到數據庫
參數化您的查詢以防止SQL注入,我敢打賭,您的問題將得到解決。 – MikeSmithDev
該怎麼辦? – Krasimir
看看這裏:http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx 參數化您的參數將保護您免受SQL注入並使您的應用程序(更多)安全。 – nimeshjm