10 个解决方案
#1
比如下一段 string source = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source='D://test.xls';Extended Properties='Excel 12.0;HDR=yes;IMEX=1'";
OleDbConnection conn = new OleDbConnection(source);
try
{
conn.Open();
string select = "SELECT * FROM [Sheet1$]";
在查询命令里必须要有表名...
OleDbConnection conn = new OleDbConnection(source);
try
{
conn.Open();
string select = "SELECT * FROM [Sheet1$]";
在查询命令里必须要有表名...
#2
String connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";
objConn = new OleDbConnection(connString);
objConn.Open();
System.Data.DataTable dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
foreach (DataRow row in dt.Rows)
{
row["TABLE_NAME"].ToString(); //就是
}
objConn = new OleDbConnection(connString);
objConn.Open();
System.Data.DataTable dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
foreach (DataRow row in dt.Rows)
{
row["TABLE_NAME"].ToString(); //就是
}
#3
+1 是不是没有指定的表名默认叫TABLE_NAME?
#4
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();//建立OpenFileDialog
dialog.Filter = "save files (*.xls)|*.xls|All files (*.*)|*.*";//设定dialog,过滤档案
dialog.InitialDirectory = "C:";//设定起始目录为C盘
dialog.InitialDirectory = Application.StartupPath;//设置起始目录为程式目录
dialog.Title = "Select a save file";//设定dialog的Title
if (dialog.ShowDialog() == DialogResult.OK)//加入使用者按下ok键,则将档案名显示在TextBox1上
{
TextBox1.Text = dialog.FileName;// selell为图中浏览按钮
}
}
{
OpenFileDialog dialog = new OpenFileDialog();//建立OpenFileDialog
dialog.Filter = "save files (*.xls)|*.xls|All files (*.*)|*.*";//设定dialog,过滤档案
dialog.InitialDirectory = "C:";//设定起始目录为C盘
dialog.InitialDirectory = Application.StartupPath;//设置起始目录为程式目录
dialog.Title = "Select a save file";//设定dialog的Title
if (dialog.ShowDialog() == DialogResult.OK)//加入使用者按下ok键,则将档案名显示在TextBox1上
{
TextBox1.Text = dialog.FileName;// selell为图中浏览按钮
}
}
#5
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();//建立OpenFileDialog
dialog.Filter = "save files (*.xls)|*.xls|All files (*.*)|*.*";//设定dialog,过滤档案
dialog.InitialDirectory = "C:";//设定起始目录为C盘
dialog.InitialDirectory = Application.StartupPath;//设置起始目录为程式目录
dialog.Title = "Select a save file";//设定dialog的Title
if (dialog.ShowDialog() == DialogResult.OK)//加入使用者按下ok键,则将档案名显示在TextBox1上
{
TextBox1.Text = dialog.FileName;// selell为图中浏览按钮
}
}
#6
好像EXCEL中的工作表名,必须指定吧,
就像MSSQL数据库那样,你必须知道表及字段名,才能进行查询工作的
就像MSSQL数据库那样,你必须知道表及字段名,才能进行查询工作的
#7
我看了网上的例子,很多都有这个TABLE_NAME,但我以为它只是一个伪代码,实际要填入表名,难道直接用TABLE_NAME就可以编译,并可读到表名?
#8
这个代码跟我的问题没什么关系
#9
能说具体点吗?直接写个TABLE_NAME?还是TABLE_NAME只是一个伪代码?实际要填入真正的表名?
#1
比如下一段 string source = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source='D://test.xls';Extended Properties='Excel 12.0;HDR=yes;IMEX=1'";
OleDbConnection conn = new OleDbConnection(source);
try
{
conn.Open();
string select = "SELECT * FROM [Sheet1$]";
在查询命令里必须要有表名...
OleDbConnection conn = new OleDbConnection(source);
try
{
conn.Open();
string select = "SELECT * FROM [Sheet1$]";
在查询命令里必须要有表名...
#2
String connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";
objConn = new OleDbConnection(connString);
objConn.Open();
System.Data.DataTable dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
foreach (DataRow row in dt.Rows)
{
row["TABLE_NAME"].ToString(); //就是
}
objConn = new OleDbConnection(connString);
objConn.Open();
System.Data.DataTable dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
foreach (DataRow row in dt.Rows)
{
row["TABLE_NAME"].ToString(); //就是
}
#3
+1 是不是没有指定的表名默认叫TABLE_NAME?
#4
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();//建立OpenFileDialog
dialog.Filter = "save files (*.xls)|*.xls|All files (*.*)|*.*";//设定dialog,过滤档案
dialog.InitialDirectory = "C:";//设定起始目录为C盘
dialog.InitialDirectory = Application.StartupPath;//设置起始目录为程式目录
dialog.Title = "Select a save file";//设定dialog的Title
if (dialog.ShowDialog() == DialogResult.OK)//加入使用者按下ok键,则将档案名显示在TextBox1上
{
TextBox1.Text = dialog.FileName;// selell为图中浏览按钮
}
}
{
OpenFileDialog dialog = new OpenFileDialog();//建立OpenFileDialog
dialog.Filter = "save files (*.xls)|*.xls|All files (*.*)|*.*";//设定dialog,过滤档案
dialog.InitialDirectory = "C:";//设定起始目录为C盘
dialog.InitialDirectory = Application.StartupPath;//设置起始目录为程式目录
dialog.Title = "Select a save file";//设定dialog的Title
if (dialog.ShowDialog() == DialogResult.OK)//加入使用者按下ok键,则将档案名显示在TextBox1上
{
TextBox1.Text = dialog.FileName;// selell为图中浏览按钮
}
}
#5
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();//建立OpenFileDialog
dialog.Filter = "save files (*.xls)|*.xls|All files (*.*)|*.*";//设定dialog,过滤档案
dialog.InitialDirectory = "C:";//设定起始目录为C盘
dialog.InitialDirectory = Application.StartupPath;//设置起始目录为程式目录
dialog.Title = "Select a save file";//设定dialog的Title
if (dialog.ShowDialog() == DialogResult.OK)//加入使用者按下ok键,则将档案名显示在TextBox1上
{
TextBox1.Text = dialog.FileName;// selell为图中浏览按钮
}
}
#6
好像EXCEL中的工作表名,必须指定吧,
就像MSSQL数据库那样,你必须知道表及字段名,才能进行查询工作的
就像MSSQL数据库那样,你必须知道表及字段名,才能进行查询工作的
#7
我看了网上的例子,很多都有这个TABLE_NAME,但我以为它只是一个伪代码,实际要填入表名,难道直接用TABLE_NAME就可以编译,并可读到表名?
#8
这个代码跟我的问题没什么关系
#9
能说具体点吗?直接写个TABLE_NAME?还是TABLE_NAME只是一个伪代码?实际要填入真正的表名?