ASP.NET绘制折线图---(2)获取数据
2010-04-28 14:28
211 查看
1.从数据库中获取数据
建立数据库连接并查询,可以专门新建一个C#类来提高代码复用率,也可以只写一个函数。下面的代码是我写的一个C#类
SQL_Connection,放在App_Code文件夹下,专门用来执行数据库操作,代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
///公用的连接数据库的类
/// </summary>
public class SQL_Connection
{
private string sql = null;
public SQL_Connection(string sql)
{
this.sql = sql;
}
public DataSet query()
{
string ConStr = "Data Source=……;Initial Catalog=……;Persist SecurityInfo=True;UserID=……;Password=……";
SqlConnection conn = new SqlConnection(ConStr);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = this.sql;
cmd.CommandTimeout = 10000;
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
conn.Close();
return ds;
}
}
2.在后台的CS文件中执行数据库查询,并将结果放在数组中,具体代码如下:
//查询数据库
string sql = "select * from manqi_cx where manqpfl <>0 and manqpfl1<>0 and manqpfl2<>0 and bmid=2";
SQL_Connection sqlCon = new SQL_Connection(sql);
DataSet ds = sqlCon.query();
//将结果放进数组中
double[] manqpfl = new double[TotalMonths];
double[] manqpfl1 = new double[TotalMonths];
double[] manqpfl2 = new double[TotalMonths];
for (int i = 0; i <ds.Tables[0].Rows.Count; i++)
{
manqpfl[i] = Convert.ToDouble(ds.Tables[0].Rows[i]["manqpfl"]);
manqpfl1[i] = Convert.ToDouble(ds.Tables[0].Rows[i]["manqpfl1"]);
manqpfl2[i] = Convert.ToDouble(ds.Tables[0].Rows[i]["manqpfl2"]);
}
本文为原创作品,转载请注明出处:http://www.cnblogs.com/luzx/
建立数据库连接并查询,可以专门新建一个C#类来提高代码复用率,也可以只写一个函数。下面的代码是我写的一个C#类
SQL_Connection,放在App_Code文件夹下,专门用来执行数据库操作,代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
///公用的连接数据库的类
/// </summary>
public class SQL_Connection
{
private string sql = null;
public SQL_Connection(string sql)
{
this.sql = sql;
}
public DataSet query()
{
string ConStr = "Data Source=……;Initial Catalog=……;Persist SecurityInfo=True;UserID=……;Password=……";
SqlConnection conn = new SqlConnection(ConStr);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = this.sql;
cmd.CommandTimeout = 10000;
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
conn.Close();
return ds;
}
}
2.在后台的CS文件中执行数据库查询,并将结果放在数组中,具体代码如下:
//查询数据库
string sql = "select * from manqi_cx where manqpfl <>0 and manqpfl1<>0 and manqpfl2<>0 and bmid=2";
SQL_Connection sqlCon = new SQL_Connection(sql);
DataSet ds = sqlCon.query();
//将结果放进数组中
double[] manqpfl = new double[TotalMonths];
double[] manqpfl1 = new double[TotalMonths];
double[] manqpfl2 = new double[TotalMonths];
for (int i = 0; i <ds.Tables[0].Rows.Count; i++)
{
manqpfl[i] = Convert.ToDouble(ds.Tables[0].Rows[i]["manqpfl"]);
manqpfl1[i] = Convert.ToDouble(ds.Tables[0].Rows[i]["manqpfl1"]);
manqpfl2[i] = Convert.ToDouble(ds.Tables[0].Rows[i]["manqpfl2"]);
}
本文为原创作品,转载请注明出处:http://www.cnblogs.com/luzx/
相关文章推荐
- 总结Asp.net中Page加载PostData的具体过程 进而解决"获取动态创建的控件的PostData数据"问题
- asp.net webapi [FromBody]string 获取不到ajax post的数据的解决方法
- 【Asp.Net从零开始】:创建主表格以及单击获取详细信息的数据显示图
- asp.net获取Post和Get数据的方法(Stream)
- AjaxPro.NET实现TextBox智能获取服务端数据功能(Asp.net 2.0)(示例代码下载)
- ASP.NET 以 Request.Querystring、Request.Form 或 Request.Params 获取客户端的数据
- Asp.Net 上传大文件专题(3)--从请求流中获取数据并保存为文件[上]
- 如何抓取到Asp.Net中-doPostBack获取新页面的数据
- asp.net获取数据随机显示(原创)
- JQuery以POST方法从ASP.NET服务器获取Json数据完整示例 .
- ASP.NET绘制折线图---(1)思路分析
- ASP.NET绘制折线图---(3)具体画图
- ASP.NET如何获取系统时间和数据功能调用
- asp.net post get 数据获取方式
- 在ASP.NET MVC的Controller Action中获取客户端请求数据
- Asp.Net实例:C# 绘制统计图(柱状图, 折线图, 扇形图)
- ASP.NET连接数据库并获取数据
- Asp.Net使用代理IP远程获取数据
- Asp.net下获取JSON数据代码
- ASP.NET MVC中 Jquery AJAX 获取数据利用MVC模型绑定实现输出