如果linq to sql不是一个选项,那么您可以返回到ado.net。实际上,您需要创建一个到数据库的连接,并创建和运行一个命令来检索所需的数据并填充一个数据表。下面是一个例子,如果C:
// Create a connection to the database
SqlConnection conn = new SqlConnection("Data Source=MyDBServer;Initial Catalog=MyDB;Integrated Security=True");
// Create a command to extract the required data and assign it the connection string
SqlCommand cmd = new SqlCommand("SELECT Column1, Colum2 FROM MyTable", conn);
cmd.CommandType = CommandType.Text;
// Create a DataAdapter to run the command and fill the DataTable
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);