把Excel数据导入到数据库
string path = null;
OpenFileDialog op = new OpenFileDialog();//实例openfiledialog
op.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
//MessageBox.Show(Path.GetFullPath("."));
if (op.ShowDialog() == DialogResult.OK)//选则文件
{
path = op.FileName;//获取文件路径
}
using (StreamReader sr = new StreamReader(path, Encoding.Default))
{
String line;
while ((line = sr.ReadLine()) != null)
{
//写入数据库(
insertdatabase(line);
}
MessageBox.Show("导入成功!");
}
private void insertdatabase(string line)
{
string[] rowtext = line.Split(",".ToCharArray());
string sqlstr = "insert into spdata values ('" + rowtext[0] + "', + rowtext[6] + "')";
SqlCeHelper.ExecuteNoQuery(sqlstr);
}
我这是把TXT文件导入数据库的代码高手能按着这些代码把 book.xls表里的 B Y二列的数据导到数据库表 spdata 里面去
麻烦各位了! 我真的非常急用!
我在线等请没有睡觉的大哥大姐们帮忙看一下!