从数据库中查询数据后赋给字符串问题 public string CheckDataYear(string logid) { string connect = "User ID=appDB;Initial Catalog=appDB;Data Source=LJJ;Password=appDB123"; SqlConnection con = new SqlConnection(connect); con.Open(); string sql= "select jyrqy from t_tzsb_ylss_ys1_new where djid='logid'"; SqlCommand com = new SqlCommand(sql,con); string year = com.ExecuteScalar().Tostring;//出错 return year; }