.NETGURU
Update table using bound text box
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.

Post a new message to this list...

gj
Hi,

I'm trying to update a sql database from a web form using text boxes.
I'm trying to learn C# on my own so I am at a complete loss. I created
my sql connection, data adapter, dataset and data view in the visual
studio designer. I'm trying to keep a history of the record so instead
of editing the record I insert a new record with my changes. Instead
of the changes, it inserts the orginal record. Below is the part of
the code. Any help would be appreiated.

else if (txtTask.Text.Trim() == "1")
{
//assign values to variables
valName = txtName.Text.ToString();
valStatus = txtStatus.Text.ToString();
valQuestionsPerPage = short.Parse(txtQuestionsPerPage.Text);
valRetakeOption = int.Parse(drpRetakeOption.SelectedValue);
valPassGrade = short.Parse(txtPassGrade.Text);
valAuthor = txtAuthor.Text.ToString();
valUserID = "jongay";
valSortType = int.Parse(drpSortType.SelectedValue);
valNotifyOptions = int.Parse(drpNotifyOptions.SelectedValue);
valGradeScale = int.Parse(drpGradeScale.SelectedValue);
valNumber = int.Parse(txtAQQuizID.Text);
valEffectiveDate = DateTime.Parse(txtEffectiveDate.Text);
valActivityDate = DateTime.Now;

dsMain.QuizRow drv = dsMain1.Quiz.NewQuizRow();
                
drv.Quiz_Name = valName;
drv.Quiz_Status = valStatus;
drv.Quiz_Questions_PerPage = valQuestionsPerPage;
drv.Quiz_PassGrade = valPassGrade;
drv.Quiz_User_ID = valUserID;
drv.Quiz_Author = valAuthor;
drv.Quiz_Activity_Date = valActivityDate;
drv.SortType_ID = valSortType;
drv.NotifyOptions_ID = valNotifyOptions;
drv.GradeScale_ID = valGradeScale;
drv.RetakeOption_ID = valRetakeOption;
drv.Quiz_Effective_Date = valEffectiveDate;
drv.Quiz_Number = valNumber;

dsMain1.Quiz.AddQuizRow(drv);

daQuiz.Update(dsMain1, "Quiz");

} //end if
Reply to this message...
 
    
Zürcher See
I think you do a DataBind() of the Controls with the DB before updating it

Let me guess:

In the OnLoad method you fill the DataSet and bind the Controls with it
In the OnClick event you try to update the DB

I'm right?

"gj" <Click here to reveal e-mail address> schrieb im Newsbeitrag
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
gj
You are right. I do fill the DataSet in the Page_Load method. Then I
do this.Databind();. When I fill out the web form and click Submit,
the value in the text box changes back to the orginal value before it
accesses my code in the OnClick event. I bound the textbox to the
DataView in Visual Studio designer using the textbox properties. Did I
do this wrong? Do I need to redo the DataBind() in the OnClick event?

Thanks

"Zürcher See" <Click here to reveal e-mail address> wrote in message news:<Click here to reveal e-mail address>...
[Original message clipped]

Reply to this message...
 
    
Zürcher See
This is my way:
In the onload method:
-fill the dataset
-if page is postback get the value from the controls and add/update them in
the dataset
-if page is not postback bind controls with the dataset

In the onclick method (for example 'save')
-Use dataadapter to update DB
-Bind controls with the dataset

On_Load()
{
...
FillDataSetWithDataAdapter();
if (!Page.IsPostback) BindControls();
else GetValueFromControlsAndUpdateDataSet();
...
}

OnClick_Save()
{
DataAdapterUpdateDataSet();
BindControls();
}

OnClick_New()
{
AddANewRowToTheDataSet();
BindControls();
}

BindControls()
{
... //here bind the controls with the dataset
}

"gj" <Click here to reveal e-mail address> schrieb im Newsbeitrag
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
gj
Thanks, I really appreciate your help.

Gayle

"Zürcher See" <Click here to reveal e-mail address> wrote in message news:<ux$Click here to reveal e-mail address>...
[Original message clipped]

Reply to this message...
 
 
System.Data.DataSet
System.Data.DataView
System.DateTime
System.Web.UI.Page




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification