连接时到是da.fill(ds)错误!!
程序代码:
public class dbbase { //static readonly string connstr = ConfigurationSettings.AppSettings["connstr"].ToString(); //static readonly string connstr = "server=.;database=student;uid=sa;pwd="; //static readonly string connstr = System.Configuration.ConfigurationManager.AppSettings["connstr"].ToString(); static readonly string connstr = "Data Source=(local);Initial Catalog=|DataDirectory|GRADE.mdf;Integrated Security=SSPI"; public dbbase() { // // TODO: 在此处添加构造函数逻辑 // } public static DataTable getDataTable(string sqlstr) { SqlConnection conn = new SqlConnection(connstr); SqlDataAdapter da = new SqlDataAdapter(sqlstr,conn); DataSet ds =new DataSet(); da.Fill(ds); return ds.Tables[0]; } public static void ExecuteSql(string sqlstr) { SqlConnection conn = new SqlConnection(connstr); SqlCommand cmd = new SqlCommand(sqlstr,conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } public static void UpdateDt(DataTable changedDt, string sqlstr) { SqlConnection conn = new SqlConnection(connstr); SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn); SqlCommandBuilder sqlCmdBuilder = new SqlCommandBuilder(da); da.Update(changedDt); changedDt.AcceptChanges(); } public static DataSet getDataSet(string sql) { SqlConnection conn = new SqlConnection(connstr); SqlDataAdapter da = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); da.Fill(ds); return ds; } } }
应该没错误才对啊!我数据库是放在App_Data里面的!!