Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

SQL data binding with DataGridView

$
0
0

Hi All,

I have binded a SQL data from SQL Server Management studio to the DataGridView using SQL connection and SQL data adapter. 

dataAdapter = new SqlDataAdapter(selectCommand, conn);
commandBuilder = new SqlCommandBuilder(dataAdapter);

dataTable = new DataTable();
dataAdapter.Fill(dataTable);

eMPBindingSource.DataSource = dataTable;
dataGridView1.DataSource = eMPBindingSource;

When i run the grid and update the SQL database using Server Management studio, the grid doesnt gets updated. I have tried to update the grid by updating the datatable using DataAdapter as below,

dataAdapter.Update(dataTable);

But the grid doesnt reflected with the added data from SQL database.

When i fill the datatable once again with dataadapter, the added data is shown in Grid.

dataAdapter.Fill(dataTable);

My question is, why the datatable didnt get updated while using Update() and gets modified while using Fill() methods. 

Is this the default behavior? If not, please anyone share me why DataTable didn't get updated when using SqpDataAdapter.Update(DataTable)....

Thanks and Regards,

Amal Raj U.


Amal Raj U


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>