M
mahajanvit
Hi one and all
I got this problem during my project. So in order to solve this I made
a very small application. I am trying to insert using SP and
sqldatasource control. I know that while using sqldatasource control,
there is no need of opening and closing a connection. Also there is no
need to write connection string. When i am selecting table from
sqldatasource and writing insert statement in C# code, its working
fine. When I am selecting SP from sqldatasource control, its not
working. While using SP i have to remove insert statement from C# Code
because same thing is there in SP. Error: SP is having too many
arguments specified. The thing is that i have only three fields in
front end and three in SP. SP is executing successfully. For ur kind
reference i am pasting the code.
protected void Btnsubmit_Click(object sender, EventArgs e)
{
string Profession = string.Empty;
string Address = string.Empty;
string City = string.Empty;
Profession = txtprofession.Text.ToString();
Address = txtaddress.Text.ToString();
City = txtcity.Text.ToString();
ParameterCollection parameters = new ParameterCollection();
SqlDataSource1.InsertParameters.Add("@Profession",
txtprofession.Text);
SqlDataSource1.InsertParameters.Add("@Address",
txtaddress.Text);
SqlDataSource1.InsertParameters.Add("@City", txtaddress.Text);
//SqlDataSource1.InsertCommand = "insert into
Name(Profession,Address,City) values ('" + Profession + "','" + Address
+ "','" + City + "')";
SqlDataSource1.Insert();
}
---------------------------------------------------------------------------------------------------------------------------------------
Stored Procedure
--------------------------
ALTER PROCEDURE Name1
(
@Profession varchar(20),
@Address varchar(100),
@City varchar(10)
)
/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
AS
insert into Name
(Profession,Address,City)values(@Profession,@Address,@City)
/* SET NOCOUNT ON */
RETURN
-------------------------------------------------------------------------------------------------------------------------
I dont know where i am making mistake. Waiting for favourable reply
from u all .NET lovers
Regards
Raghav Mahajan
Gurgaon, INDIA
(e-mail address removed)
I got this problem during my project. So in order to solve this I made
a very small application. I am trying to insert using SP and
sqldatasource control. I know that while using sqldatasource control,
there is no need of opening and closing a connection. Also there is no
need to write connection string. When i am selecting table from
sqldatasource and writing insert statement in C# code, its working
fine. When I am selecting SP from sqldatasource control, its not
working. While using SP i have to remove insert statement from C# Code
because same thing is there in SP. Error: SP is having too many
arguments specified. The thing is that i have only three fields in
front end and three in SP. SP is executing successfully. For ur kind
reference i am pasting the code.
protected void Btnsubmit_Click(object sender, EventArgs e)
{
string Profession = string.Empty;
string Address = string.Empty;
string City = string.Empty;
Profession = txtprofession.Text.ToString();
Address = txtaddress.Text.ToString();
City = txtcity.Text.ToString();
ParameterCollection parameters = new ParameterCollection();
SqlDataSource1.InsertParameters.Add("@Profession",
txtprofession.Text);
SqlDataSource1.InsertParameters.Add("@Address",
txtaddress.Text);
SqlDataSource1.InsertParameters.Add("@City", txtaddress.Text);
//SqlDataSource1.InsertCommand = "insert into
Name(Profession,Address,City) values ('" + Profession + "','" + Address
+ "','" + City + "')";
SqlDataSource1.Insert();
}
---------------------------------------------------------------------------------------------------------------------------------------
Stored Procedure
--------------------------
ALTER PROCEDURE Name1
(
@Profession varchar(20),
@Address varchar(100),
@City varchar(10)
)
/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
AS
insert into Name
(Profession,Address,City)values(@Profession,@Address,@City)
/* SET NOCOUNT ON */
RETURN
-------------------------------------------------------------------------------------------------------------------------
I dont know where i am making mistake. Waiting for favourable reply
from u all .NET lovers
Regards
Raghav Mahajan
Gurgaon, INDIA
(e-mail address removed)