Limited Update in Table
-
Hello, There are 43 textboxes on the web page of my database driven web application. Generally, what we do: (ds means dataset object) ds.Tables(0).Rows(r - 1).Item(0)=Textbox1.text ds.Tables(0).Rows(r - 1).Item(1)=Textbox2.text ... or something like it. Now suppose, if user changed the values of textbox 17,23 and/or 5,8,31; then update should be only for those column; to avoid unnecessary I/O and faster update. Is there any mean/method in ASP.NET by which we can control only limited update in table. Please guide,help and teach me. Best Regards Girish Sharma
-
Hello, There are 43 textboxes on the web page of my database driven web application. Generally, what we do: (ds means dataset object) ds.Tables(0).Rows(r - 1).Item(0)=Textbox1.text ds.Tables(0).Rows(r - 1).Item(1)=Textbox2.text ... or something like it. Now suppose, if user changed the values of textbox 17,23 and/or 5,8,31; then update should be only for those column; to avoid unnecessary I/O and faster update. Is there any mean/method in ASP.NET by which we can control only limited update in table. Please guide,help and teach me. Best Regards Girish Sharma
-
Do the text boxes have autopostback set to true?
There is no foolish question, there is no final answer...
-
No, because i think it will unnecessary increase network traffic and more request to server though.
Ok that's fine. In the button click event, just check whether the text box's value equals to the datatable rows' value or not. if it is not then only update the column else don't. Just checkout the sample code:
if(dataSet.Tables[0].Rows[8][column_name] != textBox8.Text)
{
dataSet.Tables[0].Rows[8][column_name] = textBox8.Text
}So the datatable will be updated only when the value differs from the earlier one and that means that the text box's value is changed. Is it clear? Revert back for any clarification.
There is no foolish question, there is no final answer...
-
Ok that's fine. In the button click event, just check whether the text box's value equals to the datatable rows' value or not. if it is not then only update the column else don't. Just checkout the sample code:
if(dataSet.Tables[0].Rows[8][column_name] != textBox8.Text)
{
dataSet.Tables[0].Rows[8][column_name] = textBox8.Text
}So the datatable will be updated only when the value differs from the earlier one and that means that the text box's value is changed. Is it clear? Revert back for any clarification.
There is no foolish question, there is no final answer...
Thanks for your reply; but at the last for saving the new values in the database; i will have to call adapter.update(ds); it means it will fire the complete update command. And moreover i am using following code to create dataset: Dim ods As New DataSet ods.ReadXml("C:\Inetpub\wwwroot\Exam2\Temp.xml") So, 1.will it work on the dataset and update the table ? 2.and i will have to call adapter.update(ods); means a complete update command ? What i am seeking, that after changing the values in textboxes; only those columns should be updated; rather than a complete row. Regards Girish Sharma
-
Thanks for your reply; but at the last for saving the new values in the database; i will have to call adapter.update(ds); it means it will fire the complete update command. And moreover i am using following code to create dataset: Dim ods As New DataSet ods.ReadXml("C:\Inetpub\wwwroot\Exam2\Temp.xml") So, 1.will it work on the dataset and update the table ? 2.and i will have to call adapter.update(ods); means a complete update command ? What i am seeking, that after changing the values in textboxes; only those columns should be updated; rather than a complete row. Regards Girish Sharma
The you can probably look a for writing a sql query for updating fields. You can run a for loop to check the values and after that fire the sql query only for those columns whose values are changed. DataAdapter.Update may not be a best case in this scenario.
There is no foolish question, there is no final answer...
-
The you can probably look a for writing a sql query for updating fields. You can run a for loop to check the values and after that fire the sql query only for those columns whose values are changed. DataAdapter.Update may not be a best case in this scenario.
There is no foolish question, there is no final answer...
Here one idea/approach may be using javascript. A javascript function, which will be called on textbox change event (if value changed then) with create and append a update command and then fire that update command on cliking the update button; but i do'nt have knowledge in js; just have the idea how it may worked.
-
Here one idea/approach may be using javascript. A javascript function, which will be called on textbox change event (if value changed then) with create and append a update command and then fire that update command on cliking the update button; but i do'nt have knowledge in js; just have the idea how it may worked.
-
You will not be able to access the value which is set in javascript because on the server side those values will be lost.
There is no foolish question, there is no final answer...
-
You will not be able to access the value which is set in javascript because on the server side those values will be lost.
There is no foolish question, there is no final answer...
-
Then please provide me the solution by which i can get one update command for only those columns whose textbox values has been changed by user. Kind Regards Girish Sharma
-
I already told you this: http://www.codeproject.com/Forums/12076/ASP-NET.aspx?fid=12076&select=3081044&fr=75#xx3081044xx[^]
There is no foolish question, there is no final answer...
-
But further you are agreeed that adapter.update is not best in this scnerio; so still waiting for your reply please.
I am not telling you to use DataAdapter.Update. Run a for loop and check if the textbox's value differs from the datatable's (dataset.tables[0]) value or not. if it differs then create a sqlconnection object and associate it to a sqlcommand object. Then fire a sql update query by using sqlcommand.executenonquery method. by this way, you will fire sql update for only those rows whose values are changed in the textboxes.
There is no foolish question, there is no final answer...