2015-10-30 1 views
0

Dans mes form1, je suis d'insérerDataGridView pas mise à jour après une insertion de TableAdapter

tableAdapterManager.BatchTableAdapter.Insert(Int32.Parse(Maxorder) + 10, DateTime.Now, DateTime.Now, Int32.Parse(txtData0.Value.ToString()), 1); 

il est donc ajouter à mon localdb les paramètres, puis-je aller à Form2 et il devrait montrer dans un datagridview les résultats . Cette DataGridView est avec DataSource à une vue. La vue ne montre jamais le paramètre "inséré", seulement si je redémarre l'application. J'ai essayé avec:

v_BatchTableAdapter.Fill(dbSahara.v_Batch); 

Mais je reçois seulement les données insérées avant d'ouvrir l'application.

Si quelqu'un peut m'aider ... merci d'avance.

Répondre

0

I "réparer" ce faire:

private void GetData(string selectCommand) 
    { 
     try 
     { 
      // Specify a connection string. Replace the given value with a 
      // valid connection string for a Northwind SQL Server sample 
      // database accessible to your system. 
      String connectionString = 
       "Integrated Security=SSPI;Persist Security Info=False;" + 
       "Initial Catalog=Northwind;Data Source=localhost"; 

      // Create a new data adapter based on the specified query. 
      dataAdapter = new SqlDataAdapter(selectCommand, connectionString); 

      // Create a command builder to generate SQL update, insert, and 
      // delete commands based on selectCommand. These are used to 
      // update the database. 
      SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter); 

      // Populate a new data table and bind it to the BindingSource. 
      DataTable table = new DataTable(); 
      table.Locale = System.Globalization.CultureInfo.InvariantCulture; 
      dataAdapter.Fill(table); 
      bindingSource1.DataSource = table; 

      // Resize the DataGridView columns to fit the newly loaded content. 
      dataGridView1.AutoResizeColumns( 
       DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); 
     } 
     catch (SqlException) 
     { 
      MessageBox.Show("To run this example, replace the value of the " + 
       "connectionString variable with a connection string that is " + 
       "valid for your system."); 
     } 
    } 

police: https://msdn.microsoft.com/es-es/library/vstudio/fbk67b6z(v=vs.100).aspx