Click here to Skip to main content
15,904,297 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to update/modify/replace a particular cell(Row i,Column j) in a database (MS Access)with the data entered through a textboxe in C# .please help
Posted

1 solution

Assuming you already have your connection to the Access database and where:
C#
OleDbConnection AccessCon = new OleDbConnection();
OleDbCommand cmd = default(OleDbCommand);
OleDbDataReader reader = default(OleDbDataReader);
string cmdUpdate = null;

Then something in the line of:
C#
cmdUpdate = "UPDATE TABLE_NAME " + "SET COLUMN_j = '" + TextBox1.Text + "' " + "WHERE ID(ROW_i) = " + TextBox2.Text;

cmd = new OleDbCommand(cmdUpdate);

try {
    cmd.Connection = AccessCon;
    cmd.CommandType = CommandType.Text;
    reader = cmd.ExecuteReader();
} catch (Exception ex) {
    MessageBox.Show(ex.Message);
}

reader.Dispose();

PS: I'm not a star at C#, thus the above is converted from vb.net.
 
Share this answer
 
Comments
[no name] 23-Sep-11 14:53pm    
Please clear about ID(ROW_i) and symbols ' and "
Scubapro 27-Sep-11 8:30am    
Okay. Since cmdUpdate is a string use double apostrophes.

Suppose you got the table EMPLOYEES with columns EMPLOYEE_ID and SALARY.
Your SQL will be:

cmdUpdate = "UPDATE EMPLOYEES SET SALARY = 5000 WHERE EMPLOYEE_ID = 1234"

if the columns EMPLOYEE_ID (your row i) and SALARY (your column j) are Numbers.
Use the single apostrophes (as shown earlier) if a column is a VarChar(2).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900