从 System.String 到 System.Guid 的转换无效——我怎么给指定guid类型的数据?
代码:
public string GetUsernameByUserID(string uid)
{
this.sqlCommand.CommandText="SELECT ISNULL(MAX(USERNAME),'') FROM USERINFO WHERE ID=@ID";
this.sqlCommand.Parameters.Clear();
this.sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier));
this.sqlCommand.Parameters["@ID"].Value=uid;
return sqlCommand.ExecuteScalar().ToString();
}
我的应用程序提示我
从 System.String 到 System.Guid 的转换无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidCastException: 从 System.String 到 System.Guid 的转换无效。