473,508 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to alter values in access database table using C# without adding new rows?

4 New Member
I am new in C# programming. Can anyone plz help me in the following problem.
I am changing values in different columns in access database table using c# but these changes are only visible at run time. I want to save these changes in the table without adding new rows, just want to replace old values with new ones. I'v used the "adapter.Update" command but it does not work.

Plz reply me
thankx in advance
Jul 15 '10 #1
5 4805
Christopher Nigro
53 New Member
Please show what you tried and clarify how it "does not work".
Jul 15 '10 #2
asmi
4 New Member
@Christopher Nigro
Actually this is what I am doing. this is only a chunk of my main code. "attrib_num" contains the column number where i want to insert new value in the table and "marked_attribute_dec" is the new value which i want to add in the specified column number replacing the old value.
but the code below adds new rows with the new values in the table. i want the same rows with the new values in them. In other words i want to replace some of the values of the original table rows with new column values. I dont want to have additional rows with new values. i just want to alter values in the existing rows.
please give me some suggestions. I really need assistance


[code.......

DataRow row1 = ds.Tables["Table1"].NewRow();


for (int p = 0; p <column_count; p++)
{
if (p == attrib_num)
row1[p]=marked_attribute_dec;
else

row1[p] = attributes[p];
}


ds.Tables["Table1"].Rows.Add(row1);
conn.Close();


DataTable dt = ds.Tables["Table1"];
adapterx.Update(dt);
conn.Close();
...............................code]


thanku
Jul 16 '10 #3
Christopher Nigro
53 New Member
Instead of creating a new row via NewRow(), you need to update a particular row. How do you know which row(s) need to be updated? Are the new values coming from user input in the UI or are you updating rows programatically where the rows fit some predefined criteria? Basically, you need to tell me which rows need to be updated before I can understand what you are trying to accomplish.
Jul 16 '10 #4
asmi
4 New Member
Actually I am randomly generating some numbers that indicate what specific columns or attributes of a particular row(or rows) need to be updated.
The new values are not coming from user input I am doing it programatically. My problem is how I can update those particular rows and columns with the new values I am generating.
I dont know any command for that thats why I have created new rows to make sure that my code is generating new values and iserting them at the specified row and column number correctly otherwise I can only see the changed values at run time not in the table.

I just want to know how to update existing values with new values in access table. My requirement is to update values not create extra rows which I created because I didnt have any other choice.
Jul 16 '10 #5
asmi
4 New Member
Hi Christopher,
I'v done it myself.
It was simple but it made me do alot of effort.
Heres the code

Expand|Select|Wrap|Line Numbers
  1.  
  2. for (int p = 0; p < column_count; ++p)
  3.                 {
  4.  
  5.                     if (p == attrib_num)
  6.  
  7.  
  8.            ds.Tables["Orders2"].Rows[m][p] = marked_attribute_dec;
  9.  
  10.  
  11.                 }
  12.  
  13.             }
  14. DataTable dt = ds.Tables["Orders2"];
  15. adaptery2.Update(dt);
  16. conn1.Close(); 
  17.  
  18.  
  19.  

Here "attrib_num" contains the column no. and"marked_attribute_dec" contains the value i wanted to replace in my table at the specified column no.(attrib_num).
Thanks you replyed me and found out time to consider my problem and made me consider my own logic.
Jul 18 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
506
by: Mark | last post by:
I get an error message when deleting rows from a table in Access database. My understanding is that the error message relates to the sharing of the Inetpub and the wwwroot directory. While I...
1
3413
by: sunlight_sg | last post by:
Hello, i am using ADOX + VB .NET to create a Access Database programmatically. I plan to set some properties of the column such primary key. The code is as follows: Dim cat As ADOX.Catalog...
3
2979
by: nvx | last post by:
Hello everyone... Just for the record, I'm a newbie to this data binding thing... In my C# application I need to bind a cell of an Access database table to a multiline TextBox. How should I do...
0
1677
by: OldStd | last post by:
Updating data using 2 data sets I am having some problems in updating the database using two datasets as suggested by someone. 1. Data is displayed in a data grid from a dataset generated using...
6
7590
by: kareemaffan | last post by:
Hello Everyone I want to insert values into MS Access database through VB.NET in Visual Studio 2005 . I have used the following code which is not working. Private Sub Button2_Click(ByVal sender...
8
3529
by: Bhuwan Bhaskar | last post by:
Hi, Can we access database (SQL) using AJAX ? Thanks, Bhuwan
2
4347
by: NithyaMM | last post by:
Hi, Draw table using line between rows and Columns Help me
4
13983
by: KMEscherich | last post by:
Version of Access = 2003 Hi there, is there a way to capture data using TERADATA SQL Assistant and import a portion of this database table into a Microsoft Access database table??? I currently...
4
5587
by: qwedster | last post by:
Howdy folks! I am using stored procedure to see if a value exists in database table and return 0 if exists or else -1, in the following SQL queries. However how to check if a value (that is...
2
14641
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
0
7224
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
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
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
7380
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...
1
7039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7494
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...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.