Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Stored procedure wont insert Fields, RadioButtonLists and CheckBox (http://www.velocityreviews.com/forums/t715993-stored-procedure-wont-insert-fields-radiobuttonlists-and-checkbox.html)

JB 02-25-2010 01:34 AM

Stored procedure wont insert Fields, RadioButtonLists and CheckBox
 
Hello Community

I have a CheckBox and a RadioButtonList and fields on an aspx web page form.
I pass the fields on the form to a method that creates the parameters and
executes a stored procedure and the stored procedure is supposed to insert
this information as a row into a table.

For some reason the stored procedure executes but the row does not get
inserted. I can’t see why the row doesn’t get inserted especially since I
put BreakPoints in the code all along the way and I see the values just as
they get passed into the stored procedure but maybe someone looking at this
can see why the row doesn't get inserted or have an idea why a row doesn't
insert. Note: there are more fields in this table than I am showing, these
are just some of the fields that I am inserting into the table and that are
in the table:

The only thing I could think of is maybe I can’t insert the values I am
trying to insert into the fields that are defined for the CheckBox and
RadioButtonList:

**** Initialize variable
string strSerialNumber = "";
string cbNoDispatch = " ";
int cbCaller = 0;
int rdoUsed = 0;
DateTime CallDate = new DateTime();

****get values for variable
strSerialNumber =.GetSerialNum(gval);

if (chkNoDispatch.Checked)
cbNoDispatch = "Y";
else
cbNoDispatch = "N";

if (chkCaller.Checked)
cbCaller = 0;
else
cbCaller = 1;

string tempUsed = "";
if (rdoTUsed.SelectedIndex > -1)
tempUsed = rdoUsed.SelectedItem.Value;
if (tempUsed == "No")
rdoUsed = 0;
else
rdoUsed = 1;

CallDate = DateTime.Now;

****call method that creates the parameters and calls stored procedure
InsertRow(strSerialNumber,rdoUsed, cbNoDispatch, cbCaller, dCallDateTime);

**** the method creates the parameters that go to the stored procedure
SqlParameter[] Params = {new
SqlParameter("@StrSerialNumber",strSerialNumber),
new SqlParameter("@RdoUsed",
new SqlParameter("@CbNoDispatch",cbNoDispatch),
new SqlParameter("@CbCaller", cbCaller),
new SqlParameter("@CallDate", CallDate)};

**** This is the stoed procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

alter PROCEDURE [dbo].[spInsertRow]

@StrSerialNumber varchar(50),
@RdoUsed int,
@CbNoDispatch varchar(1),
@CbCaller int,
@CallDate DateTime

AS
BEGIN
Insert into ProblemWorkItem(SerialNumber, LotsUsed, Dispatched ,
DispatchedBy, CallDate)
Values(@StrSerialNumber, @RdoUsed, @CbNoDispatch , @CbCaller, @CallDate)
END

Note: I put breakpoints in the method that creates the parameters the calls
the stored procedures so I saw the parameters values and they went to the
stored procedure when it executed. But the stored procedure didn’t return
any resultset back. By the way, the CheckBox fields in the table look like
this:

LotsUsed int <<<RadioButtonList
Dispatched char(1) Unchecked <<<CheckBox
DispatchedBy int Unchecked <<<CheckBox


What do you think?


Thanks
Jeff

--
JB

Alexey Smirnov 02-28-2010 10:30 AM

Re: Stored procedure wont insert Fields, RadioButtonLists andCheckBox
 
On Feb 25, 2:34*am, JB <J...@discussions.microsoft.com> wrote:
> Hello Community
>
> I have a CheckBox and a RadioButtonList and fields on an aspx web page form.
> I pass the fields on the form to a method that creates the parameters and
> executes a stored procedure and the stored procedure is supposed to insert
> this information as a row into a table.
>
> * * For some reason the stored procedure executes but the row does not get
> inserted. *I cant see why the row doesnt get inserted especially since I
> put BreakPoints in the code all along the way and I see the values just as
> they get passed into the stored procedure but maybe someone looking at this
> can see why the row doesn't get inserted or have an idea why a row doesn't
> insert. *Note: there are more fields in this table than I am showing, these
> are *just some of the fields that I am inserting into the table *and that are
> in the table:
>
> The only thing I could think of is maybe I cant insert the values I am
> trying to *insert into the fields that are defined for the CheckBox and
> RadioButtonList:
>
> **** Initialize variable
> * * * * string strSerialNumber = "";
> * * * * string cbNoDispatch = " ";
> * * * * int cbCaller = 0;
> * * * * int rdoUsed = 0;
> * * * * DateTime CallDate = new DateTime();
>
> ****get values for variable
> * * * * * * strSerialNumber =.GetSerialNum(gval);
>
> * * * * * * if (chkNoDispatch.Checked)
> * * * * * * * * cbNoDispatch = "Y";
> * * * * * * else
> * * * * * * * * cbNoDispatch = "N";
>
> * * * * * * if (chkCaller.Checked)
> * * * * * * * * cbCaller = 0;
> * * * * * * else
> * * * * * * * * cbCaller = 1;
>
> * * * * * * string tempUsed = "";
> * * * * * * if (rdoTUsed.SelectedIndex > -1)
> * * * * * * * * tempUsed = rdoUsed.SelectedItem.Value;
> * * * * * * if (tempUsed == "No")
> * * * * * * * * rdoUsed = 0;
> * * * * * * else
> * * * * * * * * rdoUsed = 1;
>
> * * * * * * CallDate = DateTime.Now;
>
> ****call method that *creates the parameters and calls stored procedure
> InsertRow(strSerialNumber,rdoUsed, cbNoDispatch, cbCaller, dCallDateTime);
>
> **** the method creates the parameters that go to the stored procedure
> SqlParameter[] Params = {new
> SqlParameter("@StrSerialNumber",strSerialNumber),
> * * * * * * * * * * * * *new SqlParameter("@RdoUsed",
> * * * * * * * * * * * * *new SqlParameter("@CbNoDispatch",cbNoDispatch),
> * * * * * * * * * * * * *new SqlParameter("@CbCaller", cbCaller),
> * * * * * * * * *new SqlParameter("@CallDate", CallDate)};
>
> **** This is the stoed procedure
>
> set ANSI_NULLS ON
> set QUOTED_IDENTIFIER ON
> go
>
> alter PROCEDURE [dbo].[spInsertRow]
>
> @StrSerialNumber * varchar(50),
> @RdoUsed * * * * * int,
> @CbNoDispatch * * *varchar(1),
> @CbCaller * * * * *int,
> @CallDate * * * * *DateTime
>
> AS
> BEGIN
> * * Insert into ProblemWorkItem(SerialNumber, LotsUsed, Dispatched ,
> DispatchedBy, CallDate)
> * * Values(@StrSerialNumber, @RdoUsed, *@CbNoDispatch , @CbCaller, @CallDate)
> END
>
> Note: *I put breakpoints in the method that creates the parameters the calls
> the stored procedures so I saw the parameters values and they went to the
> stored procedure when it executed. *But the stored procedure didnt return
> any resultset back. *By the way, the CheckBox fields in the table look like
> this:
>
> * * * LotsUsed * * * * *int * * * * * * *<<<RadioButtonList
> * * * Dispatched * * * * * * *char(1) * Unchecked * *<<<CheckBox
> * * * DispatchedBy * * *int * * * * * Unchecked * *<<<CheckBox
>
> What do you think?
>
> Thanks
> Jeff
>
> --
> JB


It could be that the date you passed to the sql is not in what sql
server is expected. Check if specifing the type could help

SqlParameter parameter = command.Parameters.Add("@CallDate",
System.Data.SqlDbType.DateTime);
parameter.Value = DateTime.Now;


All times are GMT. The time now is 04:55 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.