Hello forum,
I tried to show records from database in GridView control but I got an error. However, records show when I use the live database but when I switch to the local database, I get an error that says
Procedure or function has too many has too many arguments specified.
How do I resolve this?
Here is my Stored Procedure and C#
SQL
CREATE PROCEDURE [dbo].[UserData]
@PageIndex INT
,@PageSize INT
,@RecordCount INT OUT
AS
BEGIN
SELECT ROW_NUMBER() OVER(ORDER BY email) RowNumber
,Name
,email
,CreatedDate
,RoleId
,IsActive
,Suspend
INTO #Temp
FROM Users
WHERE email NOT IN('richard@gmail.com') OR CreatedBy NOT IN('richard@gmail.com')
SELECT @RecordCount = COUNT(*) FROM #Temp
SELECT * FROM #Temp
WHERE (RowNumber BETWEEN ((@PageIndex-1) * @PageSize) + 1 AND (@PageIndex * @PageSize)) OR @PageIndex = - 1
DROP TABLE #Temp
END
RETURN 0
C#
protected void Page_Load(object sender, EventArgs e)
{
if (this.Page.User.Identity.IsAuthenticated && Session["user"] != null)
{
if (!this.IsPostBack)
{
this.GetUserClientPage(1);
}
}
}
private void GetUserClientPage(int pageIndex)
{
string connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand("UserData", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@CreatedBy", createby.Text.Trim());
cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
cmd.Parameters.AddWithValue("@PageSize", PageSize);
cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4);
cmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output;
con.Open();
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
UsersGrid.DataSource = dt;
UsersGrid.DataBind();
con.Close();
int recordCount = Convert.ToInt32(cmd.Parameters["@RecordCount"].Value);
this.PopulatePager(recordCount, pageIndex);
}
}
}
}
}
protected void Page_Changed(object sender, EventArgs e)
{
int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
this.GetUserClientPage(pageIndex);
}