Add new row to Access database

  • Thread starter Thread starter kids
  • Start date Start date
K

kids

Hi all,

I wrote a simple application using C# & Ms. Access DB.
1. Read all record from database into dataset and perform searching
functionality. (work)
2. I want to add new record into the database if searching fail. (problem)
Here is the procedure:
MyTable has 2 columns only (myKey | myValue) where myKey is the PK and
myValue column is allow null.
....C# coding
private OleDbDataAdapter da;
private DataSet dsMyTable;

AddRow(string newKey){
DataTable dt = dsMyTable.Tables["MyTable"];
DataRow irow = dt.NewRow();
irow[0] = newKey;
dt.Rows.Add(irow);
da.Update(dsMyTable,"MyTable");
}

there was no error.
But when I check in MyTable I couldn't find new record added ??!!!

Please advices,
Sokun
 
I don't have dataadapter.insertcommand.
Do I need one?
Can't I update the source table from DataSet?


Miha Markic said:
Hi kids,

How does your dataadapter.insertcomand lookl like?

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

kids said:
Hi all,

I wrote a simple application using C# & Ms. Access DB.
1. Read all record from database into dataset and perform searching
functionality. (work)
2. I want to add new record into the database if searching fail. (problem)
Here is the procedure:
MyTable has 2 columns only (myKey | myValue) where myKey is the PK and
myValue column is allow null.
...C# coding
private OleDbDataAdapter da;
private DataSet dsMyTable;

AddRow(string newKey){
DataTable dt = dsMyTable.Tables["MyTable"];
DataRow irow = dt.NewRow();
irow[0] = newKey;
dt.Rows.Add(irow);
da.Update(dsMyTable,"MyTable");
}

there was no error.
But when I check in MyTable I couldn't find new record added ??!!!

Please advices,
Sokun
 
Hi,

The dataadapter is responsible for communication with database and
insertcommand is used by adapter for doing inserts.
DataSet only holds data, nothing more.
Check out
Introduction to Data Adapters
..net help topic

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

kids said:
I don't have dataadapter.insertcommand.
Do I need one?
Can't I update the source table from DataSet?


Miha Markic said:
Hi kids,

How does your dataadapter.insertcomand lookl like?

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

kids said:
Hi all,

I wrote a simple application using C# & Ms. Access DB.
1. Read all record from database into dataset and perform searching
functionality. (work)
2. I want to add new record into the database if searching fail. (problem)
Here is the procedure:
MyTable has 2 columns only (myKey | myValue) where myKey is the PK and
myValue column is allow null.
...C# coding
private OleDbDataAdapter da;
private DataSet dsMyTable;

AddRow(string newKey){
DataTable dt = dsMyTable.Tables["MyTable"];
DataRow irow = dt.NewRow();
irow[0] = newKey;
dt.Rows.Add(irow);
da.Update(dsMyTable,"MyTable");
}

there was no error.
But when I check in MyTable I couldn't find new record added ??!!!

Please advices,
Sokun
 
Back
Top