I want to pass parameters from asp.net to my stored procedure. The parameters would be the value selected by the user from the dropdownlists and then get data back from the stored procedure and display on a Gridview in asp.net when the user clicks the submit button on the webpage. An exception pops up by the Fill method when I try to debug it saying I need to pass parameters. The exception is copied below. System.Data.SqlClient.SqlException: 'Procedure or function 'Submit' expects parameter '@Address', which was not supplied.'
Below is my stored procedure
USE [Database] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [Submit] @Address varchar(12), @Number varchar(5), @Name varchar(24), @Type varchar(3) as begin select a.*, b.* from Employee as a inner join Department as b on a.Number = b.Number where a.Address = @Address and a.Number = @Number and a.name = @Name and b.Type = @Type end
Below is my .cs code
protected void Button1_Click1(object sender, EventArgs e) { con.Open(); string s = "Submit"; SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "Submit"; cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = DropDownList5.SelectedItem.Value; cmd.Parameters.Add("@Number", SqlDbType.VarChar).Value = DropDownList2.SelectedItem.Value; cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = DropDownList3.SelectedItem.Value; cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = DropDownList4.SelectedItem.Value; SqlDataAdapter da = new SqlDataAdapter(s, con); DataSet ds = new DataSet(); da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); con.Close(); }
cmd.Parameters.AddWithValue("@ParameterName", ParameterValue);
Quote:An exception pops up by the Fill method when I try to debug it saying I need to pass parameters. The exception is copied below. System.Data.SqlClient.SqlException: 'Procedure or function 'Submit' expects parameter '@Address', which was not supplied.'
null
NULL
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)