james james

james james

  • NA
  • 419
  • 29.8k

c# Refresh Access Database

Oct 31 2017 4:26 PM
I am able to Save Data to a Access databse , now when i add new entry i try to refresh the database but the new entry dont show until i close the program and open it back up. I have 2 buttons one Update and the other Refresh. I am using Parameters. It would be better to use one meathod to do both (thats over my head at the moment) so i have 2 buttons. I dont get any errors when i try to Refresh so I dont know where to start.
 
Thanks 
 
My Update code working fine.
 
  1. private void btnUpdate_Clicked(object sender, RoutedEventArgs e)  
  2.        {  
  3.            using (var myCon = new OleDbConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString()))  
  4.            {  
  5.                using (var myCmd = new OleDbCommand("insert into [Sheet1](Box1,Box2,Box3,Box4,Box5,Box6,Box7,Box8)Values(@nm1,@nm2,@nm3,@nm4,@nm5,@nm6,@nm7,@nm8)", myCon))  
  6.                {                      
  7.                    myCmd.Parameters.AddWithValue("@nm1", txt_Box1);  
  8.                    myCmd.Parameters.AddWithValue("@nm2", txt_Box2);  
  9.                    myCmd.Parameters.AddWithValue("@nm3", txt_Box3.Text);  
  10.                    myCmd.Parameters.AddWithValue("@nm4", txt_Box4.Text);  
  11.                    myCmd.Parameters.AddWithValue("@nm5", TXT_Box5.Text);  
  12.                    myCmd.Parameters.AddWithValue("@nm6", txt_Box6.Text);  
  13.                    myCmd.Parameters.AddWithValue("@nm7", txt_Box7.Text);  
  14.                    myCmd.Parameters.AddWithValue("@nm8", txt_Box8.Text);  
  15.   
  16.                    try  
  17.                    {  
  18.                        myCon.Open();  
  19.                        int z = myCmd.ExecuteNonQuery();  
  20.                        if (z > 0)  
  21.                        {  
  22.                            MessageBox.Show("Data Inserted");  
  23.   
  24.                       }  
  25.   
  26.                    }  
  27.                    catch (Exception ex)  
  28.                    {  
  29.                        //Handle exception as needed  
  30.                    }  
  31.                }  
  32.            }  
  33.   
  34.               
  35.        }  
 My Refresh is not refreshing the data base no errors givens.
 
  1. private void btn_Refresh_Click(object sender, EventArgs e)  
  2.         {  
  3.   
  4.             using (var myCon = new OleDbConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString()))  
  5.             {  
  6.                 using (var myCmd = new OleDbCommand("UPDATE Sheet1 SET Box1 =@nm1,Box2 = @nm2, Box3=@nm3, Box4 = @nm4, Box5 = @nm5,Box6  = @nm6, Box7 = @nm7 WHERE Box8 = @nm8", myCon))  
  7.                 {                      
  8.                     myCmd.Parameters.AddWithValue("@nm1", txt_Box1.Text);  
  9.                     myCmd.Parameters.AddWithValue("@nm2", txt_Box2.Text);  
  10.                     myCmd.Parameters.AddWithValue("@nm3", txt_Box3.Text);  
  11.                     myCmd.Parameters.AddWithValue("@nm4", txt_Box4.Text);  
  12.                     myCmd.Parameters.AddWithValue("@nm5", TXT_Box5.Text);  
  13.                     myCmd.Parameters.AddWithValue("@nm6", txt_Box6.Text);  
  14.                     myCmd.Parameters.AddWithValue("@nm7", txt_Box7.Text);  
  15.                     myCmd.Parameters.AddWithValue("@nm8", txt_Box8.Text);  
  16.   
  17.                     try  
  18.                     {  
  19.                         myCon.Open();  
  20.                         int z = myCmd.ExecuteNonQuery();  
  21.                         MessageBox.Show("Data Updated");  
  22.                          
  23.                     }  
  24.                     catch (Exception ex)  
  25.                     {  
  26.                         //Handle exception as needed  
  27.                     }  
  28.                 }  
  29.             }  
  30.   
  31.              
  32.         }  
 

Answers (2)