Сохранить данные из DataGrid в бд SQL
Получаю из Excel данные в datagrid, они появляются, остается их сохранить. Проблема с SqlConnection и данными пользователя. В sql так же. Вход возможен только через политику подлинности Windows
private void Button_Click_8(object sender, RoutedEventArgs e)
{
var openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Excel Files|*.xls;*.xlsx";
if ((bool)openFileDialog.ShowDialog())
{
string path = openFileDialog.FileName;
dg2.ItemsSource = _eis.EnumerateMetrics(path);
SqlConnection conn = new SqlConnection("Server=DESKTOP-4RVGC6V;Database=Clientsmfc; User Id=winapp1; Password=winapp1");
string table = "Clients";
string sql = "SELECT * FROM " + table;
adapter = new SqlDataAdapter(sql, conn);
conn.Open();
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(adapter as SqlDataAdapter);
adapter.InsertCommand = myCommandBuilder.GetInsertCommand();
adapter.UpdateCommand = myCommandBuilder.GetUpdateCommand();
adapter.DeleteCommand = myCommandBuilder.GetDeleteCommand();
dt = new DataTable();
adapter.Fill(dt);
dg2.ItemsSource = dt.DefaultView;
}
}

