刚刚学习数据库,写了一个连接SQL Sever数据库的代码,但总是连接失败,总有异常出现,看书检查,和书上也没有很么出入,实在不知道该如何去做,请大家帮忙看看
OleDbConnection subjectDatabase = new OleDbConnection();
OleDbDataAdapter subjectDaDatabase = new OleDbDataAdapter();
OleDbCommand subjectSelect = new OleDbCommand();
OleDbCommand subjectInsert = new OleDbCommand();
OleDbCommand subjectUpdata = new OleDbCommand();
OleDbCommand subjectDelete = new OleDbCommand();
DataSet subjectDset = new DataSet();
DataTable subjectDtable = new DataTable();
private void ConnectDatabase()
{
subjectDatabase.ConnectionString = "Provider=SQLOLEDB;Data Source=YIDEZHI\\SQLEXPRESS;Initial Catalog=e:\\数据库\\subject\\data\\subject.mdf;User ID=YIDEZHI;pwd=;";
DataTableMapping tableName = new DataTableMapping();
tableName = subjectDaDatabase.TableMappings.Add("Table", "suject");
subjectSelect.CommandText = "SELECT * FROM subject";
subjectSelect.Connection = subjectDatabase;
subjectDaDatabase.SelectCommand = subjectSelect;
subjectDaDatabase.Fill(subjectDset);
}
subjectDaDatabase.Fill(subjectDset)这一句总是有异常产生,不知道到底该怎么样解决,请大家帮忙看看该如何去做,谢谢。
[此贴子已经被作者于2007-10-24 14:48:06编辑过]