Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
October 8th, 2008, 02:11 PM
|
#1 (permalink)
| | Junior Member
Join Date: Oct 2008
Posts: 2
| C# Access Database Updating
Hello, I am trying to update my database. I can update it on my first pass, but after that, the database will not update. Code: Connection.Open();
SQLString = "UPDATE NodeData SET NSB=?, Type=?, Description=?, LOSrange=?, RadioTX=?, RXsens=?, AntHeight=?, AntGain=?, Frequency=? WHERE ID=?";
Command.Connection = Connection;
Command.CommandText = SQLString;
Command.CommandType = CommandType.Text;
Command.Parameters.AddWithValue("NSB", node);
Command.Parameters.AddWithValue("Type", type);
Command.Parameters.AddWithValue("Description", desc);
Command.Parameters.AddWithValue("LOSrange", los);
Command.Parameters.AddWithValue("RadioTX", txp);
Command.Parameters.AddWithValue("RXsens", rxs);
Command.Parameters.AddWithValue("AntHeight", anth);
Command.Parameters.AddWithValue("AntGain", antg);
Command.Parameters.AddWithValue("Frequency", fre);
Command.Parameters.AddWithValue("ID", kid);
try
{
int x = Command.ExecuteNonQuery();
if (x > 0)
MessageBox.Show("Database was updated");
else
MessageBox.Show("Database was not updated");
}
catch (Exception ex)
{
MessageBox.Show("Error = " + ex.ToString());
} Any help is appreciated. |
| |
October 9th, 2008, 09:52 PM
|
#2 (permalink)
| | Member
Join Date: Oct 2003
Posts: 247
|
First off you can probably just use the following...no need to declare another variable Code: if (Command.ExecuteNonQuery()>0)
MessageBox.Show("Database was updated");
else
MessageBox.Show("Database was not updated"); I am a little confused with your question....
Is it throwing an error the second time? or just not updating?
Logically just reading your question your code should work fine (considering you pass in a correct connection string and pass in the correct variables, etc.).
I would check your sql on the 2nd time around and see if it will update just using the query in msaccess.
make sure you are passing in different variables for each pass.
I just tried it using my example and everything came out cool...can you post more of code so i can get a base of all your variables and such. |
| |
October 10th, 2008, 09:23 AM
|
#3 (permalink)
| | Junior Member
Join Date: Oct 2008
Posts: 2
|
Thank you for the reply. I did find out what I was missing. I needed to have a Command.Dispose(); call in there. Once I did that, i was able to update everything. Not sure why it worked for you and not me. |
| |
October 10th, 2008, 09:38 AM
|
#4 (permalink)
| | Member
Join Date: Oct 2003
Posts: 247
|
ahh i had this code in my own sub...so it just fell out of scope. I also was using the using keyword for the command so it would automatically dispose too. |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |