public static DataTable LoadDataTable(string connectingStr, string sqlCommand)
{
SqlConnection scon = new SqlConnection(connectingStr);
//SqlConnection scon = cls_ClassLib.scon;
SqlDataAdapter sread = new SqlDataAdapter();
sread.SelectCommand = new SqlCommand(
sqlCommand,
scon
);
sread.SelectCommand.CommandTimeout = 120;
try
{
scon.Open();
}
catch (System.Exception ex)
{
if (DEBUG)
string tttt = ex.Message + sqlCommand.ToString();
else
return null;
endif
}
DataTable ds = new DataTable();
try
{
sread.Fill(ds);
}
catch (System.Exception ex)
{
try
{
//写日志
LogHelper.writeLog((Directory.GetCurrentDirectory() + "/log/" + DateTime.Now.ToString("MMdd") + "_MSSql.txt"),
DateTime.Now.ToString("HH:mm:ss") + "\t\t" + ex.Message + "\t\t" + connectingStr + "\t\t" + sqlCommand);
}
catch
{
}
if (DEBUG)
string tttt = ex.Message + sqlCommand.ToString();
else
return null;
endif
}
finally
{
try
{
sread.Dispose();
scon.Close();
}
catch
{
}
}
return ds;
}
已解决datatable中已经加载了数据