首页上一页 1 下一页尾页 2 条记录 1/1页
运行出错
发表在C#图书答疑
2009-09-18
是否精华
是
否
版块置顶:
是
否
你好!请问一个问题:
添加-新建项-本地数据库(做好了数据表),数据库连接测试成功。但运行时
报错:
错误指向conn.open(); 内容为:不可识别的数据库格式 'F:\TM\sl\15\5\Test05\Test05\db_15.sdf'。我代码里的格式并不是这样的啊!
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Test05
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string txtConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\TM\\sl\\15\\5\\Test05\\Test05\\db_15.sdf";
OleDbConnection conn = new OleDbConnection(txtConn);
conn.Open();
OleDbCommand cmd = new OleDbCommand ();
cmd.Connection = conn;
cmd.CommandText = "select * from tb_command";
cmd.CommandType = CommandType.Text;
OleDbDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
listView1.Items.Add(sdr[1].ToString());
}
conn.Dispose();
button1.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
添加-新建项-本地数据库(做好了数据表),数据库连接测试成功。但运行时
报错:
错误指向conn.open(); 内容为:不可识别的数据库格式 'F:\TM\sl\15\5\Test05\Test05\db_15.sdf'。我代码里的格式并不是这样的啊!
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Test05
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string txtConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\TM\\sl\\15\\5\\Test05\\Test05\\db_15.sdf";
OleDbConnection conn = new OleDbConnection(txtConn);
conn.Open();
OleDbCommand cmd = new OleDbCommand ();
cmd.Connection = conn;
cmd.CommandText = "select * from tb_command";
cmd.CommandType = CommandType.Text;
OleDbDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
listView1.Items.Add(sdr[1].ToString());
}
conn.Dispose();
button1.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}