小编Lar*_*inh的帖子

错误:ExecuteReader需要打开且可用的连接.连接的当前状态是打开的

我有mvc 4网站,下面有DataHelperClass来执行查询.我的问题有时候,网站通过例外作为标题.我用block来配置SqlCommand和SqlDataAdapter但没有成功.

请帮帮我,抱歉我的英语.

        try
        {
            if (_conn.State == ConnectionState.Closed)
                _conn.Open();

            using (SqlCommand sqlCommand = new SqlCommand(query, _conn))
            {
                sqlCommand.CommandType = CommandType.StoredProcedure;

                if (parameters != null)
                    sqlCommand.Parameters.AddRange(parameters);

                //// check transaction is exist
                if (_trans != null)
                    sqlCommand.Transaction = _trans;

                DataTable dt = new DataTable();
                using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand))
                {
                    sqlDataAdapter.Fill(dt);
                }

                return dt;
            }
        }
        finally
        {
            //// close connection automatically if transaction is not exist
            if (_trans == null) { _conn.Close(); }
        }
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc-4

11
推荐指数
1
解决办法
3万
查看次数

Excel.Chart.Export 不起作用

我有一张 Excel 文件,其中包含多个图表。我从Excel中获取图表并将其保存到图片中。

我的代码:

workSheet = workBook.Sheets[1] as Excel._Worksheet;
Excel.ChartObjects chartObjects =(Excel.ChartObjects)workSheet.ChartObjects(Type.Missing);
int chartCount = chartObjects.Count;
for (int j = 1; j <= chartCount; j++)
{
     Excel.ChartObject chart = (Excel.ChartObject)chartObjects.Item(j);
     path = Path.Combine(Application.StartupPath, @"Img\" + chart.Chart.Name + ".bmp");
     chart.Chart.Export(path, "BMP", true);
}
Run Code Online (Sandbox Code Playgroud)

但只导出空白图片。

请帮我

c# excel

5
推荐指数
1
解决办法
3498
查看次数

标签 统计

c# ×2

asp.net-mvc-4 ×1

excel ×1