PavelGur
Programmer
- Sep 21, 2001
- 75
I'm new to C# coming from C++ 6.0. I need to insert data into MS Access table. I was able to read data from table with Reader. However when I try to insert simple one item I've got from one table into another table it runs w/o errors but data is not in the table.
Here is my code:
Thank you for any help, Pavel.
Here is my code:
Code:
private static string szItem;
public static void Main()
{
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\MyStuff\\Money\\New Market\\NSTXP.mdb");
OleDbDataAdapter dAdapter = new OleDbDataAdapter();
OleDbCommand aCommand = new
OleDbCommand("select Stock from STGEN", aConnection);
OleDbCommand bCommand = new
OleDbCommand("select Symbol from Symbols", aConnection);
try
{
aConnection.Open();
OleDbDataReader aReader = aCommand.ExecuteReader();
while(aReader.Read())
{
szItem = aReader.GetString(0);
bCommand = new
OleDbCommand("INSERT INTO Symbols (Symbol) " +
"VALUES (@value)", aConnection);
bCommand.Parameters.Add("@value", OleDbType.Char, 5, szItem);
dAdapter.InsertCommand = bCommand;
}
aReader.Close();
aConnection.Close();
}