i got this error:
Procedure or function 'consultant_Update' expects parameter '@Consultant_Id', which was not supplied.
create procedure consultant_Update
(
@name varchar(50),
@Phone_Number varchar(50),
@Address varchar(50),
@City varchar(50),
@State varchar(50),
@Zip_Code varchar(50),
)
AS
BEGIN
update consultant set
name = @name,
Phone_Number = @Phone_Number,
Address =@Address,
City = @City,
State = @State,
Zip_Code = @Zip_Code where Consultant_Id = @Consultant_Id
END
GO
Loading
Sanjeeb LenkaPosted Jul 8, 2013, 9:07 AM
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["ConsultantId"] != null)
ViewState["ConsultantId"]= int.Parse(Request.QueryString["ConsultantId"]);
}
}
in update:
btnupdate_Click(object sender, EventArgs e)
{
SqlCommand cmdupdate = new SqlCommand("consultant_Update", con); cmdupdate.CommandType = CommandType.StoredProcedure; cmdupdate.Parameters.AddWithValue("@Consultant_Id",
Convert.ToInt32(ViewState["ConsultantId"])); cmdupdate.Parameters.AddWithValue("@name", txtname.Text.ToString()); cmdupdate.Parameters.AddWithValue("@Phone_Number", txtphonenumber.Text.ToString()); cmdupdate.Parameters.AddWithValue("@Address", txtaddress.Text.ToString()); cmdupdate.Parameters.AddWithValue("@City", txtcity.Text.ToString()); cmdupdate.Parameters.AddWithValue("@State", txtstate.Text.ToString()); cmdupdate.Parameters.AddWithValue("@Zip_Code", txtzipcode.Text.ToString());
con.opn();
cmdupdate.ExecuteNonQuery();
con.close();
}
Sanjeeb LenkaPosted Jul 8, 2013, 10:04 AM
manjula dPosted Jul 8, 2013, 9:31 AM
manjula dPosted Jul 8, 2013, 9:01 AM
{
if (!IsPostBack)
{
if (Request.QueryString["ConsultantId"] != null)
ConsultantId = int.Parse(Request.QueryString["ConsultantId"]);
}
}
Sanjeeb LenkaPosted Jul 8, 2013, 8:56 AM
manjula dPosted Jul 8, 2013, 8:50 AM
manjula dPosted Jul 8, 2013, 8:45 AM
Iftikar HussainPosted Jul 8, 2013, 8:39 AM
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 8, 2013, 8:35 AM
example-
exec consultant_Update 1,'manjula','amerpet','hyb','AP','50004'
execute like this and see its updating or not pass the existing consultantID
manjula dPosted Jul 8, 2013, 8:33 AM
Iftikar HussainPosted Jul 8, 2013, 8:28 AM
SqlCommand cmdupdate = new SqlCommand("consultant_Update", con); cmdupdate.CommandType = CommandType.StoredProcedure;
cmdupdate.Parameters.AddWithValue("@Consultant_Id", ConsultantId);
Regards,
Iftikar
manjula dPosted Jul 8, 2013, 8:26 AM
[Consultant_Id] [int] IDENTITY(1,1) NOT NULL PrimaryKey,
[Name] [varchar](50) NULL,
[Phone_Number] [varchar](50) NULL,
[Address] [varchar](50) NULL,
[City] [varchar](50) NULL,
[State] [varchar](50) NULL,
[Zip_Code] [varchar](50) NULL,
codebehind:
btnupdate_Click(object sender, EventArgs e)
{
SqlCommand cmdupdate = new SqlCommand("consultant_Update", con); cmdupdate.CommandType = CommandType.StoredProcedure; cmdupdate.Parameters.AddWithValue("@Consultant_Id", ConsultantId); cmdupdate.Parameters.AddWithValue("@name", txtname.Text.ToString()); cmdupdate.Parameters.AddWithValue("@Phone_Number", txtphonenumber.Text.ToString()); cmdupdate.Parameters.AddWithValue("@Address", txtaddress.Text.ToString()); cmdupdate.Parameters.AddWithValue("@City", txtcity.Text.ToString()); cmdupdate.Parameters.AddWithValue("@State", txtstate.Text.ToString()); cmdupdate.Parameters.AddWithValue("@Zip_Code", txtzipcode.Text.ToString());
con.opn();
cmdupdate.ExecuteNonQuery();
con.close();
}
in thease code when btnupdate was clicked the data was not updaing to DATABASE
Iftikar HussainPosted Jul 8, 2013, 8:23 AM
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 8, 2013, 8:21 AM
manjula dPosted Jul 8, 2013, 8:19 AM
Iftikar HussainPosted Jul 8, 2013, 8:17 AM
alter procedure consultant_Update
(
@name varchar(50),
@Phone_Number varchar(50),
@Address varchar(50),
@City varchar(50),
@State varchar(50),
@Zip_Code varchar(50),
@Consultant_Id int
)
AS
BEGIN
update consultant set
name = @name,
Phone_Number = @Phone_Number,
Address =@Address,
City = @City,
State = @State,
Zip_Code = @Zip_Code where Consultant_Id = @Consultant_Id
END
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 8, 2013, 8:09 AM
i modified the stored procedure just check
create procedure consultant_Update
(
@Consultant_Id Int,
@name varchar(50),
@Phone_Number varchar(50),
@Address varchar(50),
@City varchar(50),
@State varchar(50),
@Zip_Code varchar(50),
)
AS
BEGIN
update consultant set
name = @name,
Phone_Number = @Phone_Number,
Address =@Address,
City = @City,
State = @State,
Zip_Code = @Zip_Code where Consultant_Id = @Consultant_Id
END
GO
if Consultant_Id in varchar the take parameter as @Consultant_Id varchar(50)