菜鸟编写的用datagrid显示excel的WPF程序,始终显示using指令错误,求高手解答。
已经using System.Windows.Forms了,为什么程序还出现如下错误呢?
错误 1 “System.Windows.Controls.DataGrid”不包含“DataSource”的定义,并且找不到可接受类型为“System.Windows.Controls.DataGrid”的第一个参数的扩展方法“DataSource”(是否缺少 using 指令或程序集引用?)
错误 2 “System.Windows.Controls.DataGrid”不包含“DataMember”的定义,并且找不到可接受类型为“System.Windows.Controls.DataGrid”的第一个参数的扩展方法“DataMember”(是否缺少 using 指令或程序集引用?)
VS2010 4.0FW 环境
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
//using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Data.OleDb;
namespace ElevationCalculation
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.textBoxInput.Text = @"线路设计数据文件.xlsx";
}
private void buttonSelectInput_Click(object sender, RoutedEventArgs e)
{
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.openFileDialog1.Filter = "线路设计数据(xlsx)|*.xlsx";
this.openFileDialog1.FileName = this.textBoxInput.Text;
if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
this.textBoxInput.Text = this.openFileDialog1.FileName;
}
private void buttonReadInput_Click(object sender, RoutedEventArgs e)
{
string filePath = this.textBoxInput.Text;
string strConn;
strConn = @"Provider=Microsoft.Ace.OleDb.12.0;" +
@"Data Source=filePath;" +
@"Extended Properties=Excel 12.0;";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [施工右线坡度$]", strConn);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet);
this.dataGrid1.DataSource = myDataSet;
this.dataGrid1.DataMember = myDataSet.Tables.TableName;
}
private System.Windows.Forms.OpenFileDialog openFileDialog1;
}
}
@"Data Source=filePath;"改为@"Data Source=" + filePath+ ";"
页:
[1]