private void BindDataGridView() { try { var select = "SELECT DISTINCT [Country],[State],[City] FROM dbo.StaffRecord ORDER BY [Country] ASC,[State] DESC"; var c = new SqlConnection(connstring); var dataAdapter = new SqlDataAdapter(select, c); var ds = new DataSet(); dataAdapter.Fill(ds); dataGridView1.ReadOnly = true; dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
<add name="connection" connectionString = "Data Source=(localdb)\MSSQLLocalDB; Initial catalog=StaffRecord; Integrated Security=true;AttachDBFilename=|DataDirectory|\Database1.mdf;" providerName="System.Data.SqlClient" />
Quote:To connect to a specific database by using the file name, connect using a connection string similar to Server=(LocalDB)\MSSQLLocalDB; Integrated Security=true ;AttachDbFileName=D:\Data\MyDB1.mdf.
Quote:This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)