Look at the two different ways you use the SP:
Quote:
var cmd = new SqlCommand("usercrudoperation", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@status", "GET");
con.Open();
var data_adapter = new SqlDataAdapter(cmd);
var data_set = new DataSet();
data_adapter.Fill(data_set); // got error
And
var cmd = new SqlCommand("usercrudoperation", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@username", user.userid);
cmd.Parameters.AddWithValue("@education", user.education);
cmd.Parameters.AddWithValue("@location", user.location);
cmd.Parameters.AddWithValue("@Status", "Insert");
con.Open();
ViewData["result"] = cmd.ExecuteNonQuery();
In t6he first case, you supply only one parameter and get an error.
In the second you supply four parameters, and (presumably) don't.
A quick look at the SP definition:
Create Procedure usercrudoperation
(
@username varchar(50),
@education varchar(50),
@location varchar(50),
@status varchar(10)
)
As
Shows that it expects four parameters, and that none of them can be null. Parameters you do not provide are passed as null values, so you get an error.
Either provide all the parameters, or change your SP to allow nulls values for the three you do not pass.