Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am updating a table using another table such that when one table doesn't contain a value the other table is updated.
The Query that I am using is:
Update History set Termination_date = 'date', Termination_time = 'time', Link_Status='1' WHERE Name NOT IN (SELECT NAME FROM IP_State_Down)

When used via ACCESS the Query works like magic but when it is embedded like this:
string Date1 = System.DateTime.Now.ToShortDateString();
            string Time1 = System.DateTime.Now.ToLongTimeString();
            string DateTime1 = Date1 + " " + Time1;
            string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\Database\\aharchi.mdb";
            OleDbConnection conn = new OleDbConnection(connStr);
            OleDbCommand com = new OleDbCommand();
            conn.Open();
            com.Connection = conn;
            com.CommandText = "Update History set Termination_date = 'Date1', Termination_time = 'Time1', Link_Status='1' WHERE Name NOT IN (SELECT NAME FROM IP_State_Down)";
            com.ExecuteNonQuery();
            conn.Close();

the code doesn't work like it's intended. Please let me know what to do

I am really sorry ALL!!!! The problem was identified to be from another part of the program not this piece
Posted
Updated 21-Mar-13 4:25am
v5
Comments
ZurdoDev 20-Mar-13 12:15pm    
If that is the literal code you are running I would guess it is failing on trying to put the word "Hello" into the Termination_date field, which I am assuming is a date field. Are you getting errors?
09hadi 20-Mar-13 12:18pm    
No there is no error. The field is Long Text. So there is no error. As the code runs the whole History table get new termination time for every record.
ZurdoDev 20-Mar-13 12:26pm    
So, dumb question but are you sure your code is pointing to the same database that you are manually looking in?
09hadi 20-Mar-13 12:27pm    
yes

1 solution

Hi,

(...) the code doesn't work like it's intended (...)

Probably because:

C#
string Date1 = System.DateTime.Now.ToShortDateString();
string Time1 = System.DateTime.Now.ToLongTimeString();
string DateTime1 = Date1 + " " + Time1;
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\Database\\aharchi.mdb";
OleDbConnection conn = new OleDbConnection(connStr);
OleDbCommand com = new OleDbCommand();
conn.Open();
com.Connection = conn;
com.CommandText = "Update History set Termination_date = '" + Date1 + "', Termination_time = '" + Time1 + "', Link_Status='1' WHERE Name NOT IN (SELECT NAME FROM IP_State_Down)";
com.ExecuteNonQuery();
conn.Close();


Pay attention to the code with bold.

Good luck.
 
Share this answer
 
v2
Comments
Maciej Los 21-Mar-13 13:10pm    
Eagle eye, +5!

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