当我在调试时运行我的代码时,我收到了这个错误:
从字符串转换为唯一标识符时转换失败
这是代码:
public class UserObject
{
private string m_name = string.Empty;
public UserObject(string id)
{
#region Internal Logic
try
{
using (SqlConnection cn = new SqlConnection(SiteConfig.ConnectionString))
{
string sSQL = "SELECT [UserName] FROM [aspnet_users] WHERE [UserID] = @UserID";
using (SqlCommand cm = new SqlCommand(sSQL, cn))
{
cm.Parameters.AddWithValue("@UserID", id);
cn.Open();
using (SqlDataReader rd = cm.ExecuteReader())
{
while (rd.Read())
{
m_name = rd[0].ToString();
}
rd.Close();
}
cn.Close();
}
}
}
catch (Exception ex)
{
}
#endregion Internal logic
}
}