using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsFormsApplication1 { public partial class Form1 : Form { SqlDataAdapter sda; SqlCommandBuilder scb; DataTable dt; public Form1() { InitializeComponent(); } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void button2_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=C:/Program Files (x86)/Microsoft SQL Server Compact Edition/v3.5/Samples/Northwind.sdf;"); sda = new SqlDataAdapter(@"SELECT [Order ID], [Customer ID], [Employee ID], [Ship City], [Ship Region], [Ship Postal Code], [Ship Country], [Ship Via], [Order Date], [Required Date], [Shipped Date], Freight, [Ship Name], [Ship Address] FROM Orders", con); dt = new DataTable(); sda.Fill(dt); dataGridView1.DataSource = dt; } private void button1_Click(object sender, EventArgs e) { scb = new SqlCommandBuilder(sda); sda.Update(dt); } } } The problem is that when you press the button, the program freezes and after a while this error appears:
There was a network or instance error while connecting to SQL Server. Server not found or unavailable. Ensure that the instance name is correct and that remote connections are allowed on SQL Server. (provider: Named Pipes Provider, error: 40 - Failed to open connection to SQL Server)
And it is shown that the program stops at this stage - sda.Fill(dt); . What to do, tell me?