473,394 Members | 1,769 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,394 software developers and data experts.

Update table using bound text box

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
Nov 16 '05 #1
4 2705
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" <jo****@boystown.org> schrieb im Newsbeitrag
news:4f**************************@posting.google.c om...
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

Nov 16 '05 #2
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" <aq****@cannabismail.com> wrote in message news:<Ox**************@tk2msftngp13.phx.gbl>...
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" <jo****@boystown.org> schrieb im Newsbeitrag
news:4f**************************@posting.google.c om...
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

Nov 16 '05 #3
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" <jo****@boystown.org> schrieb im Newsbeitrag
news:4f**************************@posting.google.c om...
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" <aq****@cannabismail.com> wrote in message

news:<Ox**************@tk2msftngp13.phx.gbl>...
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" <jo****@boystown.org> schrieb im Newsbeitrag
news:4f**************************@posting.google.c om...
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

Nov 16 '05 #4
gj
Thanks, I really appreciate your help.

Gayle

"Zürcher See" <aq****@cannabismail.com> wrote in message news:<ux**************@TK2MSFTNGP15.phx.gbl>...
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" <jo****@boystown.org> schrieb im Newsbeitrag
news:4f**************************@posting.google.c om...
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" <aq****@cannabismail.com> wrote in message

news:<Ox**************@tk2msftngp13.phx.gbl>...
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" <jo****@boystown.org> schrieb im Newsbeitrag
news:4f**************************@posting.google.c om...
> 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

Nov 16 '05 #5

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

Similar topics

3
by: PAUL EDWARDS | last post by:
I have a windows form that is bound to a datatable. In VB6 I could just update the field contents and it would be updated in the database, however if I update the text property of the control from...
2
by: Joe Fetters via .NET 247 | last post by:
Have googled and read the VS.NET documentation can't seem to getthe answer to the following. Environment: Framework 1.1 VB.NET WinForm Access database Using all automagic tools (DataAdapter...
0
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
5
by: PAUL EDWARDS | last post by:
I have a windows form that is bound to a datatable. In VB6 I could just update the field contents and it would be updated in the database, however if I update the text property of the control from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.