无法将参数值从字符串转换为 Guid c# aspx
Failed to convert parameter value from a String to a Guid c# aspx
我正在尝试获取当前页面的当前 GUID 并将该值保存到 SQL。当页面加载时,它会在标签中加载 GUID。所以我想从标签中获取 GUID 并放入 sql 但它给了我错误:无法将参数值从字符串转换为 Guid。这是我的代码:
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);
}
改为
OGTeamparam[0].Value = htAMTeam["AccountGUID"];
使用
OGTeamparam[0].Value = new Guid((string)htAMTeam["AccountGUID"]);
我已经开始工作了,成功了:
OGTeamparam[0].Value = new Guid(Convert.ToString(htAMTeam["AccountGUID"]));
我正在尝试获取当前页面的当前 GUID 并将该值保存到 SQL。当页面加载时,它会在标签中加载 GUID。所以我想从标签中获取 GUID 并放入 sql 但它给了我错误:无法将参数值从字符串转换为 Guid。这是我的代码:
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);
}
改为
OGTeamparam[0].Value = htAMTeam["AccountGUID"];
使用
OGTeamparam[0].Value = new Guid((string)htAMTeam["AccountGUID"]);
我已经开始工作了,成功了:
OGTeamparam[0].Value = new Guid(Convert.ToString(htAMTeam["AccountGUID"]));