Inserting Record Problem

T

thebison

Hi all,

I hope someone can help with this relatively simple problem.
I am building a timesheet application using ASP.NET C# with Visual
Studio 2003.As it is only a protoype application, my database has been
made in MSDE.

I have a 'Create Resource' page where new employees are added to the
database. On my data-entry form I capture all the standard details for
the Resource table. I have two drop down boxes which are data bound and
populated with department IDs and manager IDs from other tables
(datasets). I have a stored procedure for inserting a new resource, and
when I click the 'Submit' button everything seems to work. However when
I look at the values inserted to the Resource table, everything is
correct apart from the two drop-down values which have defaulted to
'1', even when I select '3', or '4' or any other option in the
drop-down list. Whatever I do, when the record is written, it defaults
to the value of '1'.

The code for writing these two elements in the insert is:

sqlParam = cmd.Parameters.Add("@ManagerID", SqlDbType.Int, 4);

sqlParam.Value = ddManager.SelectedValue;


sqlParam = cmd.Parameters.Add("@DeptID", SqlDbType.Int, 4);

sqlParam.Value = ddDept.SelectedValue;

The weird thing is that when I use the same code on another form for a
drop-down which has 'hard-coded' values in the drop down list this
works fine.

Any help would be much appreciated! I'm sure it's something simple!

Thanks

Al
 
T

thebison

Hi
Thanks for your quick reply. Here is the aspx code for the two DropDown
lists. If I was to hard code the values into the dropdowns, the Insert
statement would insert whichever value I selected, however when I do it
as below, it inserts the value '1' (the first option) whichever value I
select in the drop down. Very strange.

<asp:dropdownlist id=ddManager style="Z-INDEX: 133; LEFT: 136px;
POSITION: absolute; TOP: 288px" tabIndex=7 runat="server" Width="172px"
DataValueField="ManagerID" DataSource= said:
</asp:dropdownlist>


<asp:dropdownlist id=ddDept style="Z-INDEX: 135; LEFT: 136px; POSITION:
absolute; TOP: 336px" tabIndex=8 runat="server" Width="172px"
DataValueField="DeptID" DataSource="<%# dsDeptName1
%>"></asp:dropdownlist>


Hope you can help, thanks again!

Al
 
J

Jim Andersen

thebison said:
the two drop-down values which have defaulted to
'1', even when I select '3', or '4' or any other option in the
drop-down list. Whatever I do, when the record is written, it defaults
to the value of '1'.

You sure you dont have a re-bind of those DDboxes somewhere ? Like in the
pageload event ? Someplace you call Databind ?

/jim
 
T

thebison

Jim,

Thanks for your reply. You are right! It was because (being a careless
newbie) i had forgotten the

if(!IsPostBack)

in my page_load..

It now works!

Thanks!
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top