0
Workbook workbook = new Workbook();
workbook.LoadFromFile(FileNameDb);
Worksheet sheet = workbook.Worksheets[0];
DataTable dataTable = sheet.ExportDataTable();
DataView view = new DataView(dataTable);
dataGridView1.ItemsSource = view;

string str;
for (int i = 0; i < dataGridView1.Items.Count - 1; i ++)
{
str = "Insert Into Sample(MCC, MNC, LAC, CellId, CellIdAddress, LAT, LONG, Network) 
                   Values(" + dataGridView1.Rows[i].Cells[0].Value.ToString() + ", '" + 
                              dataGridView1.Rows[i].Cells[1].Value.ToString() + "'," + 
                              dataGridView1.Rows[i].Cells[2].Value.ToString() + "," + 
                              dataGridView1.Rows[i].Cells[3].Value.ToString() + "," + 
                              dataGridView1.Rows[i].Cells[4].Value.ToString() + "," + 
                              dataGridView1.Rows[i].Cells[5].Value.ToString() + "," + 
                              dataGridView1.Rows[i].Cells[6].Value.ToString() + "," + 
                              dataGridView1.Rows[i].Cells[7].Value.ToString() + ")";
    command = new SQLiteCommand(str, m_dbConnection);
    command.ExecuteNonQuery();
}

But Rows here give me error data grid does not contain a definition for Rows and after reading every line add that line in sqlite database

Ajay Gupta
  • 1,775
  • 1
  • 10
  • 22
So2
  • 17
  • 7

2 Answers2

0

the following code hopefully worked

foreach (DataGridCellInfo di in dgDataGrid.SelectedCells) 
{
    DataRowView dvr = (DataRowView)di.Item;

    MessageBox.Show(dvr[1].ToString()); 
}
0

using loop on datagrid like

for(int i = 0; i<=datagrid.Items.length;i++) { string name = ((your object) datagrid.Items[i]).name; }

  • This is just an example if you bind your wpf grid control with list have attributes name, address , location then with this you can access name row wise. And your object in this case will be customer – MuhammadWaseem Jul 19 '18 at 07:21