[英]Passing GUID through C# as parameter to Crystal Reports throws an error
[英]Passing GUID parameter into a SQL function which accepts Guid parameter in c#
我已使用會話從上一頁獲取值。 即UserId
,然后嘗試將此值傳遞給SQL的GetDataByUserId(@guidparam)
函數。 然后將該獲取的值傳遞到網格視圖,如下所述。
錯誤:
無法啟用約束。 一或多個行包含違反非null,唯一或外鍵約束的值。
請幫我解決這個問題。
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DSRolesTableAdapters.aspnet_RoleUsersTableAdapter userRoleAdapter = new DSRolesTableAdapters.aspnet_RoleUsersTableAdapter();
DataTable dt = new DataTable();
Guid user = Guid.NewGuid();
user = Guid.Parse(Session["UserId"] as string);
dt = userRoleAdapter.GetDataByUserId(user);//Error at this line
UserRolesGrdView.DataSource = dt;
UserRolesGrdView.DataBind();
}
}
對於通信來說,這有點長。
問題出在Datatable
你是通過返回userRoleAdapter.GetDataByUserId
,你已經定義了一些unique
或not null
不屬於compatable與您正在從數據庫中檢索數據上的限制,我的意思是在填充時的datatable
的一些數據與違反這些約束和程序給錯誤。 刪除DataTable上不需要的所有內容,非null和唯一約束(設置allow null=true
且is unique=false
),它將修復。
注意:另外, number of fields
, length
和number of fields
的datatype
應與您試圖填充數據表的數據兼容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.