|This is supposed to be simple.
I have a very simple stored proc which selects records based on ID provided by user.
ALTER PROCEDURE [dbo].[sp_getcheck]
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
If NOT EXISTS(select * from mytable where ID=@ID)
'ID number entered %d is invalid',
What we would like to do is have user enter an ID and check to see if it exists on our database.
If yes, user is redirected to a page of his/her choice.
If no, we would like to keep user on same screen with a message that ID number entered Q1254 is invalid.
That error is raised on the stored procedure and we would like C# code to display that message on the screen for the user.
Here is that code:
protected void chk_Click(object sender, EventArgs e)
SqlConnection Conn = default(SqlConnection);
Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Constr"].ConnectionString);
SqlCommand cmd = new SqlCommand("sp_getcheck", Conn);
SqlParameter outPutParameter = new SqlParameter();
SqlDataReader dr = cmd.ExecuteReader();
imgstatus.ImageUrl = "images/Icon_Available.gif";
lblStatus.ForeColor = Color.Green;
var evalue = hequipID.Value;
if (evalue == "1")
if (evalue == "2")
catch (SqlException ex)
imgstatus.ImageUrl = "images/NotAvailable.jpg";
lblStatus.ForeColor = Color.Red;
lblStatus.Text = ex.Message;
chk.BackColor = Color.Silver;
en I tried to run the code, I get the following error message:
Procedure or function 'sp_getchech' expects parameter '@ID', which was not supplied
Surely I am doing something wrong.
Any ideas how to resolve this?
Thanks in advance
modified 9-Aug-17 11:47am.