2015-10-30 2 views
0

В моих Form1, я вставивDataGridView не обновляется после вставки из TableAdapter

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

так это добавление к моей LocalDB параметров, а затем я иду в form2 и он должен показать в DataGridView результаты , Этот DataGridView связан с DataSource для представления. В представлении никогда не отображается параметр «вставленный», только если я перезагружаю приложение. Я пробовал с:

v_BatchTableAdapter.Fill(dbSahara.v_Batch); 

Но я только вставил данные перед открытием приложения.

Если кто-то может мне помочь ... спасибо заранее.

ответ

0

I "отремонтировали" он это делает:

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."); 
     } 
    } 

шрифта: https://msdn.microsoft.com/es-es/library/vstudio/fbk67b6z(v=vs.100).aspx

Смежные вопросы