博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET调用存储过程
阅读量:5745 次
发布时间:2019-06-18

本文共 1309 字,大约阅读时间需要 4 分钟。

Creat PROCEDURE [dbo].[abc] @s varchar(8000), @e varchar(8000) AS declare @sql1 varchar(8000) set @sql1 = 'select Name as n' select @sql1 = @sql1 + ',sum(case Subject when ''' + Subject + ''' then Result else 0 end) [' + Subject + ']' from (select distinct Subject from cj) as a set @sql1 ='select Name,sum(result) 总分,'+right(@sql1,len(@sql1)-17)+' from cj WHERE RESULT BETWEEN '+@s+' AND '+@e+' group by name' exec(@sql1) exec abc 70,80
using System.Data.SqlClient; using System.Configuration; using System.Data; protected void Button1_Click(object sender, EventArgs e) {
  using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))   {
  conn.Open();   SqlDataAdapter sqldap = new SqlDataAdapter();   SqlCommand cmm = new SqlCommand();   cmm.Connection = conn;   cmm.CommandType = CommandType.StoredProcedure;   cmm.CommandText = "abc";   cmm.Parameters.Add("s", SqlDbType.VarChar);   cmm.Parameters.Add("e", SqlDbType.VarChar);   cmm.Parameters["s"].Value = TextBox1.Text;   cmm.Parameters["e"].Value = TextBox2.Text;   sqldap.SelectCommand = cmm;   DataTable dt = new DataTable();   sqldap.Fill(dt);   GridView2.DataSource = dt;   GridView2.DataBind();   } }

就这么处理!

转载于:https://www.cnblogs.com/ibgo/archive/2012/04/04/2432513.html

你可能感兴趣的文章