Stored procedure wont insert Fields, RadioButtonLists and CheckBox

J

JB

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
 
G

Guest

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

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top