Call EndCurrentEdit on the dataset...?
Main Topics
Browse All TopicsI have a form with multiple fields. The form can either be in edit mode or new record mode depending on the value of Session("ConsultantTimeID"
Adding a new record works fine. However, if an existing record is passed to the form (i.e. Session("...ID") = 78), the new values are not captured. Below is my code
For instance, if I bring up a record where hours = 2.5 and I change it to 3 and set a breakpoint that assigns txtTime.Text to the parm value, it still shows 2.5
I tried setting autopostback on txtTime just to see if that might fix it, but it just reloaded the original value for the field.
I don't know if this is relevant, but to populate the form (in edit mode), I fill a dataset and use it's only datarow to populate the various fields. I'll put that code below just in case anyone needs it.
Thanks so much for any help!
---------------save code----------------------
Dim cmd As SqlCommand, StoredProc As String
'put code here to update the record if that's what's happening...
If Session("ConsultantTimeID"
StoredProc = "InsertConsultantTimeRecor
Else
StoredProc = "UpdateConsultantTimeRecor
End If
'Try
cmd = New SqlCommand(StoredProc, Session("cn"))
cmd.CommandType = CommandType.StoredProcedur
'add stored proc parameters
If Session("ConsultantTimeID"
cmd.Parameters.Add("@Consu
End If
cmd.Parameters.Add("@Clien
cmd.Parameters.Add("@Proje
cmd.Parameters.Add("@UserI
cmd.Parameters.Add("@TaskI
cmd.Parameters.Add("@WorkD
cmd.Parameters.Add("@EndDa
cmd.Parameters.Add("@Hours
cmd.Parameters.Add("@After
cmd.Parameters.Add("@Notes
cmd.Parameters.Add("@Billa
cmd.Parameters.Add("@Trave
cmd.Parameters.Add("@Trave
cmd.Parameters.Add("@Miles
cmd.Parameters.Add("@Milea
cmd.Parameters.Add("@CarRe
cmd.Parameters.Add("@Tolls
cmd.Parameters.Add("@Perso
cmd.Parameters.Add("@Busin
cmd.Parameters.Add("@Custo
cmd.Parameters.Add("@LastM
cmd.ExecuteNonQuery()
---------------end save code----------------------
--------------form field populate code----------------------
Dim dt As DataTable, drow As DataRow
dt = TimeRecordDs.Tables(0)
drow = dt.Rows(0)
'first, figure out frmClientID
frmClientID = drow("ClientID")
'populate the project drop down for this client id
Call LoadProjectDropDown()
'the dropdowns...
drpProjects.SelectedValue = drow("projectid")
If drow("TaskID") > 0 And drow("taskID") <> Nothing Then
drpTasks.SelectedValue = drow("taskid")
Else
drpTasks.SelectedValue = 1 'general
End If
'the text fields...
txtWorkDate.Text = frmDataRow("WorkDate")
txtEndDate.Text = frmDataRow("WorkDate")
txtTime.Text = frmDataRow("Hours")
txtDescription.Text = frmDataRow("Notes")
chkBillable.Checked = frmDataRow("Billable")
chkAfterHours.Checked = frmDataRow("AfterHours")
txtTravelFrom.Text = frmDataRow("TravelFrom")
txtTravelFrom.Text = frmDataRow("TravelFrom")
txtTravelTo.Text = frmDataRow("TravelTo")
txtTravelMiles.Text = frmDataRow("Miles")
txtTotalMileageCost.Text = frmDataRow("MileageCost")
txtCarRental.Text = frmDataRow("CarRental")
txtTollsParking.Text = frmDataRow("TollsParking")
txtPersonalMeals.Text = frmDataRow("PersonalMeals"
txtBusinessExpenses.Text = frmDataRow("BusinessExpens
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Make sure you are not populating the control values from the database after the page postback. This would explain why the value would be set to 2.5. You should not be loading from the db on postback. pseudo code...
if its not a postback..
if I have a db key..
get the data and populate
end if
end if
if it is a post back..
do an update
end if
Business Accounts
Answer for Membership
by: MrDeveloperPosted on 2003-10-27 at 13:18:27ID: 9629890
sorry, had some junk code left in the form population part. it should read:
) es") ts")
ord", ConfigurationSettings.AppS ettings("c n"))
mmandType = CommandType.StoredProcedur e
rameters.A dd(New SqlParameter("@ConsultantT imeID", SqlDbType.VarChar)) rameters(" @Consultan tTimeID"). Value = Session("ConsultantTimeID" )
s)
s(0)
'first, figure out frmClientID
frmClientID = frmDataRow("ClientID")
'populate the project drop down for this client id
Call LoadProjectDropDown()
'the dropdowns...
drpProjects.SelectedValue = frmDataRow("projectid")
If frmDataRow("TaskID") > 0 And frmDataRow("taskID") <> Nothing Then
drpTasks.SelectedValue = frmDataRow("taskid")
Else
drpTasks.SelectedValue = 1 'general
End If
'the text fields...
txtWorkDate.Text = frmDataRow("WorkDate")
txtEndDate.Text = frmDataRow("WorkDate")
txtTime.Text = frmDataRow("Hours")
txtDescription.Text = frmDataRow("Notes")
chkBillable.Checked = frmDataRow("Billable")
chkAfterHours.Checked = frmDataRow("AfterHours")
txtTravelFrom.Text = frmDataRow("TravelFrom")
txtTravelFrom.Text = frmDataRow("TravelFrom")
txtTravelTo.Text = frmDataRow("TravelTo")
txtTravelMiles.Text = frmDataRow("Miles")
txtTotalMileageCost.Text = frmDataRow("MileageCost")
txtCarRental.Text = frmDataRow("CarRental")
txtTollsParking.Text = frmDataRow("TollsParking")
txtPersonalMeals.Text = frmDataRow("PersonalMeals"
txtBusinessExpenses.Text = frmDataRow("BusinessExpens
txtCustomerComments.Text = frmDataRow("CustomerCommen
and the code to get the data in the first place...
'get data for frmConsultantTimeID and populate the fields
TimeRecordDs = New DataSet
Dim MyAdapter As SqlDataAdapter
MyAdapter = New SqlDataAdapter("GetTimeRec
MyAdapter.SelectCommand.Co
MyAdapter.SelectCommand.Pa
MyAdapter.SelectCommand.Pa
MyAdapter.Fill(TimeRecordD
frmDataRow = TimeRecordDs.Tables(0).Row