设为首页 加入收藏

TOP

ASP.NET+d3.js实现Sqlserver数据库的可视化展示(二)
2019-09-17 18:23:53 】 浏览:64
Tags:ASP.NET d3.js 实现 Sqlserver 数据库 可视化 展示
/
打开连接 Con.Open(); //调用存储过程 Com = new SqlCommand("exportUserAnsawer", Con); //设置命令的类型为存储过程 Com.CommandType = CommandType.StoredProcedure; // 设置参数 Com.Parameters.Add("@id", SqlDbType.Int); Com.Parameters.Add("@filepath", SqlDbType.VarChar); // 注意输出参数要设置大小,否则size默认为0 Com.Parameters.Add("@re", SqlDbType.Int, 10); // 设置参数的类型为输出参数,默认情况下是输入, Com.Parameters["@re"].Direction = ParameterDirection.Output; // 为参数赋值 Com.Parameters["@id"].Value = id; Com.Parameters["@filepath"].Value = filepath; // 执行 Com.ExecuteNonQuery(); // 得到输出参数的值,把赋值给re,注意,这里得到的是object类型的,要进行相应的类型转换 re = (int)Com.Parameters["@re"].Value; if (re == 1) return true; else return false; } catch (Exception e){ // Console.WriteLine(e.ToString()); return false; } } }

3.在后端(测试结果.cs)文件中,创建文件名,路径,用户ID。这些变量可以从其他页面的Session中获取,我这里就写死了(方便演示)。

测试结果.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    String filepath=null;
    String userID = null;
    String username = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        userID = ""+5;
        username = "clientuser1";

        //插入数据完成后导出csv文件
        filepath = getFilePath(username, userID);
        DB db2 = new DB();
        if (db2.exportQueryUserAnsawer(Convert.ToInt16(userID), filepath))
        {
            Response.Write("<script>alert('保存文件成功');</script>");
        }
        else
        {
            Response.Write("<script>alert('?保存文件失败');</script>");

        }
        //转相对路径
        filepath = urlconvertor(filepath);

        //以上变量可从session中获取
        //try
        //{
        //    username = Session["ClientUsername"].ToString();
        //    userID = Session["ClientUserID"].ToString();
        //    filepath = Session["FliePath"].ToString();
        //    filepath = urlconvertor(filepath);
        //   // Response.Write(filepath + "<br/>");
        //}
        //catch
        //{
        //    Response.Write("<script>alert('请先登录!');;window.location.href='登录.aspx';</script>");
        //    return;
        //}

        //设置以下属性是为了,实现与js数据交互
        this.name.Text = username;
        this.name.ToolTip = username;
        this.path.ToolTip = filepath;
    }

    //退出登录
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Response.Redirect("登录.aspx");
    }

     //生成文件物理路径 如下
    //F:\Demo\Data\username_5_answer_2019-05-08_18-29-48-792.csv

    protected String getFilePath(String username,String userID ) {
        String year = DateTime.Now.Year.ToString();
        String mouth = DateTime.Now.Month.ToString();
        String day = DateTime.Now.Day.ToString();
        String houre = DateTime.Now.Hour.ToString();
        String minute = DateTime.Now.Minute.ToString();
        String second = DateTime.Now.Second.ToString();
        String millsecond = DateTime.Now.Millisecond.ToString();
        if (Convert.ToInt16(mouth) < 10) mouth = "0" + mouth;
        if (Convert.ToInt16(day) < 10) day = "0" + day;
        String date = year + "-" + mouth + "-" + day + "_" + houre + "-" + minute + "-" + second + "-" + millsecond;
        /
首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇在 ASP.NET Core 项目中使用 npm .. 下一篇【C#夯实】我与接口二三事:IEnum..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目