'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code. Procedure or function 'usp_checklist_select' expects parameter '@system',which was not supplied. WHERE DID I GO WRONG IN THE CODE?
RSS
Your statement is wrong, you should use EXEC instead of Update.
The code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.AllowPaging = true;
GridView1.PageSize = 15;
GridView1.AllowSorting = false;
BindGridView();
}
}
private void BindGridView()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constr527"].ToString()))
{
DataSet leo = new DataSet();
string sql = "EXEC dbo.uspGetAddress @Price = 'P1'";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
conn.Open();
//SqlCommand cmd = new SqlCommand();
//cmd.Connection = conn;
//cmd.CommandText = "UPDATE usp_checklist_select SET task_system = @System";
//cmd.CommandType = CommandType.Text;
//cmd.Parameters.Add("@System", SqlDbType.Char, 3);
da.Fill(leo);
GridView1.DataSource = leo;
GridView1.DataBind();
}
}
STORED PROCEDURE:
CREATE PROCEDURE dbo.uspGetPrice @Price nvarchar(30)
AS
SELECT * FROM Test3
WHERE Price = @Price
GO
The result:
Best regards,
Sam
IIS.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
None
0 Points
2 Posts
'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code...
Jun 12, 2019 02:20 PM|Elapache1032|LINK
I AM TRYING TO DISPLAY A GRIDVIEW WITH THE GIVEN INFORMATION FROM THE DATABASE AND STORED PROCEDURE
CODE C#
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Checklist
{
public partial class Checklists : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{
GridView1.AllowPaging = true;
GridView1.PageSize = 15;
GridView1.AllowSorting = false;
BindGridView();
}
}
private void BindGridView()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["VOICE"].ToString()))
{
DataSet leo = new DataSet();
string strSelectCmd = "usp_checklist_select";
SqlDataAdapter da = new SqlDataAdapter(strSelectCmd, conn);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "UPDATE usp_checklist_select SET task_system = @System";
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@System", SqlDbType.Char, 3);
da.Fill(leo, "usp_checklist_select");
DataView list = leo.Tables["usp_checklist_select"].DefaultView;
GridView1.DataSource = list;
GridView1.DataBind();
}
}
protected void checklistDS_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
}
protected void checklistDS_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
}
protected void gridview_RowUpdating(object sender, GridViewUpdatedEventArgs e)
{
}
}
}
STORED PROCEDURE:
ALTER PROCEDURE [dbo].[usp_checklist_select]
-- Add the parameters for the stored procedure here
@System char(3)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT [task_id]
,[task_system]
,[task_time]
,[task_name]
,[task_status]
,[task_sched]
,[task_comment]
,[task_startendmonth]
,[task_hreflink]
,[task_signedoffby]
,[task_signedoffdatetime]
FROM [dbo].[checklist_master]
WHERE task_system = @System
END
Contributor
3370 Points
1409 Posts
Re: 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user...
Jun 13, 2019 10:06 AM|samwu|LINK
Hi Elapache1032,
Your statement is wrong, you should use EXEC instead of Update.
The code:
STORED PROCEDURE:
The result:
Best regards,
Sam