日期:2014-05-17 浏览次数:20955 次
public DataTable Mydatatable(string s3) { DataTable inv = new DataTable(); inv.Clear(); try { ReConnection(); if (sqlcn.State == ConnectionState.Open) { using (SqlCommand sqlcom3 = new SqlCommand(s3, this.sqlcn)) { SqlDataReader sdr = sqlcom3.ExecuteReader(); inv.Load(sdr); sqlcom3.Dispose(); sdr.Dispose(); sdr.Close(); } } else if (olecn.State == ConnectionState.Open) { using (OleDbCommand olecom2 = new OleDbCommand(s3, this.olecn)) { OleDbDataReader oledr = olecom2.ExecuteReader(); inv.Load(oledr); olecom2.Dispose(); oledr.Dispose(); oledr.Close(); } } errflag = false; return inv; } catch(Exception err) { errflag = true; return inv; throw err; } }
DataTable dt1 = new DataTable(); select_st1 = "select ScTime from sRecords where ScTime in (select max(ScTime) from sRecords)"; dt1 = access_con1.Mydatatable(select_st1); DataTableReader dbreader = new DataTableReader(dt1); dbreader.Read(); st1 = Convert.ToString(dbreader.GetValue(dbreader.GetOrdinal("ScTime")));