2
我試圖獲取當前頁面的當前GUID並將值保存到SQL中。當頁面加載時,它將GUID加載到標籤中。所以我想從標籤中取出GUID並放入到sql中,但它給了我錯誤:無法將參數值從字符串轉換爲Guid。這是我的代碼:無法將參數值從字符串轉換爲Guid c#aspx
protected void btnAddOGCoverageTeamMembers_Click(object sender, EventArgs e)
{
try
{
string AccountGUID = base.Request["account"];
guidget.Text = AccountGUID.ToString();
Hashtable htAMTeam = new Hashtable();
htAMTeam["GUID"] = guidget.Text;
htAMTeam["UserID"] = Convert.ToInt32(Person.SelectedValue);
htAMTeam["Location"] = Location.SelectedValue;
htAMTeam["Product"] = Product.Text;
obj.addTeam(htAMTeam);
}
catch (Exception ex)
{
lblMsg.Text = ex.Message;
}
}
這是代碼隱藏頁:頁面的.cs
public void addTeam(Hashtable htAMTeam)
{
SqlParameter[] OGTeamparam = new SqlParameter[4];
OGTeamparam[0] = new SqlParameter("@AccountGUID", SqlDbType.UniqueIdentifier);
OGTeamparam[1] = new SqlParameter("@UserID", SqlDbType.Int);
OGTeamparam[2] = new SqlParameter("@Location", SqlDbType.VarChar, 50);
OGTeamparam[3] = new SqlParameter("@Product", SqlDbType.VarChar, 50);
OGTeamparam[0].Value = htAMTeam["AccountGUID"];
OGTeamparam[1].Value = htAMTeam["UserID"].ToString();
OGTeamparam[2].Value = htAMTeam["Location"].ToString();
OGTeamparam[3].Value = htAMTeam["Product"].ToString();
SqlHelper.ExecuteNonQuery(OGconnection, CommandType.StoredProcedure, "InsertAccountOGTeam", OGTeamparam);
}
我得到這個錯誤:CS0246:類型或命名空間名稱「GUID」找不到(是否缺少using指令或程序集引用?) –
@ParbhuBissessar是我不好,我missspelled GUID。使用Guid。我編輯了我的答案。 – BWA
感謝和抱歉我得到了另一個錯誤:'System.Guid.Guid(byte [])'的最佳重載方法匹配有一些無效參數 –