I need to compare filenames(.mdf) with existing databases on SQL server, but I don't know how. The databases that are not attached must show in datagridview.
Here is the code so far:
private void loadDB_Click_1(object sender, EventArgs e)
{
String[] files = Directory.GetFiles(@"C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\", "*.mdf", SearchOption.AllDirectories);
DataTable table = new DataTable();
table.Columns.Add("File Name");
table.Columns.Add("Path");
for (int i = 0; i < files.Length; i++)
{
FileInfo file = new FileInfo(files[i]);
table.Rows.Add((Path.GetFileNameWithoutExtension(file.Name)),Path.GetFullPath(file.Name));
}
dataGridView2.DataSource = table;
}