我们可以使用Asp.net前端在Sql server中创建存储过程 [英] Can we create a Stored Procedure in Sql server Using Asp.net Front End

查看:94
本文介绍了我们可以使用Asp.net前端在Sql server中创建存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



考虑我有一个带有两个文本框和一个按钮的网页。

如果我输入Spname,EmpName,EmpSalary在文本框中单击保存然后

应该在带有Spname的Sqlserver中创建一个sp,并且应该在sp中选择

语句。





有可能吗?



谢谢所有

等待你的response ....

Hi Everyone,

Consider i have a webpage with two textboxes and one button.
If i enter Spname,EmpName,EmpSalary in the textboxes and click on Save then
An sp should be created in the Sqlserver with Spname and should have a select
statement in the sp.


Is it possible?

Thanks All
Awaiting your response....

推荐答案

using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string __conStr = @"Data Source=(local)\S2005;Initial Catalog=Demo;Integrated Security=SSPI";

            using (SqlConnection con = new SqlConnection(__conStr))
            {
                con.Open();

                string __spName = "MyUsp";
                string __tblName = "Customers";
                string __sQuery = "";

                __sQuery += "CREATE PROCEDURE " + __spName + "\r\nAS\r\n";
                __sQuery += "Begin\r\n";
                __sQuery += "SELECT * FROM " + __tblName + "\r\n";
                __sQuery += "End\r\n";

                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = __sQuery;

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch { }

                con.Close();
            }
        }
    }
}


这篇关于我们可以使用Asp.net前端在Sql server中创建存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆