This is my UserRoleList.aspx.cs Code where i am passing the session variable to the page Default.aspx.cs
And the error is:
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
I have gone through many pages , and tried by making the AllowDbNull property making True and then different things.
Please help me out, where am i making the mistake and aslo suggest, if their any alternative
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Forms_RolesMgt_RoleList_UserRoleList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["userName"] == null)
Response.Redirect("~/Login.aspx");
if (!Page.IsPostBack)
{
if (!Page.User.IsInRole("Others_Roles_Add"))
Response.Redirect("~/unauthorized.aspx");
getUserRoles();
}
}
private void getUserRoles()
{
DSRolesTableAdapters.aspnet_RoleUsersTableAdapter userRoleAdapter = new DSRolesTableAdapters.aspnet_RoleUsersTableAdapter();
DataTable dt= new DataTable();
dt = userRoleAdapter.GetDataUser();
UserGridView.DataSource = dt;
UserGridView.DataBind();
}
protected void UserNameIdGrdView_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Send(object sender, EventArgs e)
{
GridViewRow gr = ((sender as LinkButton).NamingContainer as GridViewRow);
Session["UserId"] = gr.Cells[0].Text.Trim();
Session["UserName"] = gr.Cells[1].Text.Trim();
Response.Redirect("~/Forms/RolesMgt/RoleList/Default.aspx");
}
}
This is the code of the second page Default.aspx.cs where i have to user the session varaible to pass in the SQL fucntion named GetDataByUserId as shown below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlTypes;
public partial class Forms_RolesMgt_RoleList_Default : System.Web.UI.Page
{
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);
Response.Write(user);
dt = userRoleAdapter.GetDataByUserId(user);//er//ror coming at this line
UserRolesGrdView.DataSource = dt;
UserRolesGrdView.DataBind();
}
}
}