473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Inserting Record Problem

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

Mar 13 '06 #1
4 1311
Please try pasting your aspx code i mean your
Dropdownlists etc..
Patrick

"thebison" <al************@btinternet.com> wrote in message
news:11**********************@j52g2000cwj.googlegr oups.com...
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

Mar 14 '06 #2
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="<%# dsManagerName1 %>"
</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

Mar 14 '06 #3

"thebison" <al************@btinternet.com> skrev i en meddelelse
news:11**********************@j52g2000cwj.googlegr oups.com...
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
Mar 14 '06 #4
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!

Mar 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Greg Ofiesh | last post by:
Anyone who can help, I have two tables T1 and T2. T1 has fields K1 and F2 and T2 has fields K2 and F1. F1 is the foreign key relating to K1 and F2 is the foreign key relating to K2. My...
1
by: ing42 | last post by:
I have a problem with inserting records into table when an indexed view is based on it. Table has text field (without it there is no problem, but I need it). Here is a sample code: USE test GO...
3
by: veerapureddy | last post by:
Hai everybody, i like to insert some records into database from html form by entering data.my problem is how can i check , whether a record is available in database about a particular...
5
by: bob44 | last post by:
Hi, I recently created a mysql database using phpmyadmin. I then proceeded to make a form to insert data into the database, but the problem is that the form is only able to insert one record, and...
3
by: Surya | last post by:
Dear All, I have problem on inserting a record to database..Although it looked easy.. i have caught up with following issue .. please go ahead and help me to find solution I Need to insert...
20
by: dav3 | last post by:
Alright folks I am in need of a lil guidance/assistance here. I have a program which reads in a txt file. This txt file contains lines of the form January 3, 2007, 85.8 Now each line of the txt...
5
by: dos360 | last post by:
Hello, I have two tables, one is a list of activities, the other a list of participants. I want to insert one record in the activities table and then using its identity column as foreign key, I...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
5
by: rando1000 | last post by:
Okay, here's my situation. I need to loop through a file, inserting records based on a number field (in order) and if the character in a certain field = "##", I need to insert a blank record. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.