本文介绍了ExecuteReader:尚未初始化Connection属性。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! DatabaseClass dqwb = new DatabaseClass(); dqwb.dbConnection( (local), 常规, DWSS123 -PC, dwss123); // SqlConnection myConnection1 = new SqlConnection(Server =(local); Database = General; Trusted_Connection = True;); // myConnection1.Open(); // SqlCommand com ; string str; 尝试 { // com = new SqlCommand(); SqlCommand com = new SqlCommand ( 从dbo.CompanyYear中选择YearLabel); dqwb.openConnection(); // com.CommandText =从dbo.CompanyYear中选择YearLabel; SqlDataAdapter sda = new SqlDataAdapter(com); SqlDataReader reader = com.ExecuteReader(); DataTable dt = new DataTable(); DataSet ds = new DataSet(); ds.Tables.Add(dt); } public void dbConnection( string ProjectName112, string databasenameName112, string user12, string pass12) { string strProject = ProjectName112; // 输入您的SQL服务器实例名称 string strDatabase = databasenameName112; // 输入您的数据库名称 string strUserID = user12; // 输入您的SQL Server用户名 string strPassword = pass12; // 输入您的SQL Server密码 // string strProject = a; //输入您的SQL服务器实例名称 // string strDatabase = b; //输入您的数据库名称 // string strUserID = c; //输入您的SQL Server用户名 // string strPassword = d; //输入您的SQL Server密码 string strconn = data source = + strProject + ; database = + strDatabase + ; Persist Security Info = True;用户ID = + strUserID + ; Password = + strPassword + ;; conn = new SqlConnection(strconn); } 解决方案 DatabaseClass dqwb = new DatabaseClass(); dqwb.dbConnection("(local)", "General", "DWSS123-PC", "dwss123"); //SqlConnection myConnection1 = new SqlConnection("Server=(local);Database=General;Trusted_Connection=True;"); //myConnection1.Open(); //SqlCommand com; string str; try { //com = new SqlCommand(); SqlCommand com = new SqlCommand("select YearLabel from dbo.CompanyYear"); dqwb.openConnection(); //com.CommandText = "select YearLabel from dbo.CompanyYear"; SqlDataAdapter sda = new SqlDataAdapter(com); SqlDataReader reader = com.ExecuteReader(); DataTable dt = new DataTable(); DataSet ds = new DataSet(); ds.Tables.Add(dt);} public void dbConnection(string ProjectName112, string databasenameName112, string user12,string pass12) { string strProject = ProjectName112; //Enter your SQL server instance name string strDatabase = databasenameName112; //Enter your database name string strUserID = user12; // Enter your SQL Server User Name string strPassword = pass12; // Enter your SQL Server Password //string strProject = a; //Enter your SQL server instance name //string strDatabase = b; //Enter your database name //string strUserID = c; // Enter your SQL Server User Name //string strPassword = d; // Enter your SQL Server Password string strconn = "data source=" + strProject + ";database=" + strDatabase + ";Persist Security Info=True;User ID=" + strUserID + ";Password=" + strPassword + ";"; conn = new SqlConnection(strconn); } 解决方案 这篇关于ExecuteReader:尚未初始化Connection属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-01 20:19