using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace SQLServerDAL //可以修改成实际项目的命名空间名称
{
 
    public abstract class DbHelperSQL
    {
      
        protected static string connectionString = @"Data Source=.;Initial Catalog=SGPZ;User Id=sa;Password=abc.123";
        public DbHelperSQL()
        {
        }

public static DataSet RunProc(DataTable dt)
        {

SqlConnection userConnection = new SqlConnection(connectionString);
            SqlCommand userCommand = new SqlCommand("p_student", userConnection);
            userCommand.CommandType = CommandType.StoredProcedure;//采用存储过程
            userCommand.Parameters.Add("@tstudent", SqlDbType.Structured);//存储过程参数
            userCommand.Parameters["@tstudent"].Value = dt;//给参数赋值
            userCommand.Connection.Open();

SqlDataAdapter adapter = new SqlDataAdapter(userCommand);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            return ds;
        }

/**/
        /// <summary>
        /// 执行查询语句,返回DataSet
        /// </summary>
        /// <param name="SQLString">查询语句</param>
        /// <returns>DataSet</returns>
        public static DataSet Query(string SQLString)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                DataSet ds = new DataSet();
                try
                {
                    connection.Open();
                    SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
                    command.Fill(ds, "ds");
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    throw new Exception(ex.Message);
                }
                return ds;
            }
        }

}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Data.SqlClient;

namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

private void Form1_Load(object sender, EventArgs e)
        {

}

private void button1_Click(object sender, EventArgs e)
        {
          
            System.Diagnostics.Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start(); //  开始监视代码运行时间

DataSet dt = SQLServerDAL.DbHelperSQL.Query("select  * from student ");
            dataGridView1.DataSource = SQLServerDAL.DbHelperSQL.RunProc( dt.Tables[0]).Tables[0].DefaultView;

stopwatch.Stop(); //  停止监视
            TimeSpan timespan = stopwatch.Elapsed; //  获取当前实例测量得出的总时间
            double hours = timespan.TotalHours; // 总小时
            double minutes = timespan.TotalMinutes;  // 总分钟
            double seconds = timespan.TotalSeconds;  //  总秒数
            double milliseconds = timespan.TotalMilliseconds;  //  总毫秒数
            MessageBox.Show(seconds.ToString());
        }

}

}

USE [SGPZ]
GO
/****** Object:  StoredProcedure [dbo].[p_student]    Script Date: 07/05/2013 17:19:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[p_student]
@tstudent  tstudent READONLY
AS
begin
SELECT * INTO #tstudent  FROM @tstudent
UPDATE #tstudent SET STUNAME='周杰伦'
SELECT * FROM #tstudent
DROP TABLE #tstudent
END

sql表值参数的更多相关文章

  1. SQL Server 2008 表变量参数(表值参数)用法

    表值参数是 SQL Server 2008 中的新参数类型.表值参数是使用用户定义的表类型来声明的.使用表值参数,可以不必创建临时表或许多参数,即可向 Transact-SQL 语句或例程(如存储过程 ...

  2. SQL Server 2008 表值参数用法

    下面的示例使用 Transact-SQL 并演示如何执行以下操作:创建表值参数类型,声明变量来引用它,填充参数列表,然后将值传递到存储过程. USE AdventureWorks; GO /*创建表值 ...

  3. SQLServer使用表值参数,高性能批量插入数据

    记得前段时间帮同事写了个解析账号并入库的小工具,来批量导入账号信息,账号量相当大,程序每读取一条记录便执行一次insert来插入数据,整整跑了一下午才把账号全部入库. 今天又接到同事类似的需求,不过这 ...

  4. 在C#应用程序中,利用表值参数过滤重复,批量向数据库导入数据,并且返回重复数据

    在很多情况下,应用程序都需要实现excel数据导入功能,数据如果只有几十条,或上百条,甚至上千条,速度还好. 但是不仅如此,如果客户提供给你的excel本身存在着重复数据,或是excel中的某些数据已 ...

  5. 用SqlParameter 给SQL传递参数

    1.数据访问层 using的用法: 01.可以using System;导命名控空间 02.using 的语法结构 using(变量类型  变量名 =new 变量类型()) { } 案例: 03.us ...

  6. SQL表值函数和标量值函数的区别

    SQL表值函数和标量值函数的区别 写sql存储过程经常需要调用一些函数来使处理过程更加合理,也可以使函数复用性更强,不过在写sql函数的时候可能会发现,有些函数是在表值函数下写的有些是在标量值下写的, ...

  7. Liferay中SQL打印参数

      XX\tomcat-7.0.42\webapps\ROOT\WEB-INF\classes\log4j.properties log4j.rootLogger=INFO, CONSOLE log4 ...

  8. C#中SQL语句参数写法

    OracleConnection oc=new OracleConnection("data source=osserver;User Id=****;password=**"); ...

  9. C# 数据库批量插入数据之 —— SqlBulkCopy、表值参数

    创建了一个用来测试的Student表: CREATE TABLE [dbo].[Student]( [ID] [int] PRIMARY KEY NOT NULL, ) NULL, ) NULL, [ ...

随机推荐

  1. KVM调整cpu和内存

    一.修改kvm虚拟机的配置 1.virsh edit centos7 找到“memory”和“vcpu”标签,将 <name>centos7</name> <uuid&g ...

  2. LeetCode 136. Single Number(只出现一次的数字)

    LeetCode 136. Single Number(只出现一次的数字)

  3. Xpath,XQuery,DTD

    一.Xpath XPath 是一门在 XML 文档中查找信息的语言;XPath 是 XSLT 中的主要元素.XPath是W3C标准.1.七种类型节点:元素.属性.文本.命名空间.处理指令.注释.文档节 ...

  4. chakra在vs2017中编译出现的问题

    转:http://blog.csdn.net/ink_cherry/article/details/73437981 1.无法找到vs2010生成工具 MSB8020 无法找到 Visual Stud ...

  5. 转: CreateProcessAsUser 0xC0000005访问冲突问题

    转:http://blog.csdn.net/glc22/article/details/77227367   在使用CreateProcessAsUser时出现了 0xC0000005访问冲突问题, ...

  6. mac linux 命令笔记 - 权限管理

    壹 权限 在使用命令行工具时,可能需要临时切换到管理员/root权限,如何切换呢? 正文 进入 root 权限: sudo -i 提示输入密码,这个密码就是锁屏的解锁密码. 在操作完成之后,使用 ex ...

  7. ARM开发板搭建NFS网络文件共享方法

    前边 已经提到过吧vmare的IP改成了静态IP,对于上网来说,这个是个麻烦的事.现在重新配置Vmware的IP VMware-Edit-Virtual network editor 选择PC机的无线 ...

  8. 切换java版本

    First, clean your project: Project > Clean If that doesn't fix things... Second check your projec ...

  9. 在树莓派3B上安装node.js

    本文主讲如何在树莓派3B上安装node.js 环境描述1. 树莓派安装了`2016-11-25-raspbian-jessie-lite`(PS:在此版本的镜像中,默认禁用了ssh,在烧录好镜像之后, ...

  10. CentOS6永久修改主机名称

    1.修改network vi /etc/sysconfig/network 修改HOSTNAME值 2.修改hosts vi /etc/hosts 修改中间的那个localhost 3.使用hostn ...