如何在SQL Server 2005的pl/sql中接受用户输入 [英] how to take user input in pl/sql of sql server 2005

查看:126
本文介绍了如何在SQL Server 2005的pl/sql中接受用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在sql server 2005的pl/sql中接受用户输入
请给我一个例子

how to take user input in pl/sql of sql server 2005
please give me a example

推荐答案

您应该使用Parametrized query从用户那里获取输入,然后检索数据.
样本:
You should use Parametrized query to take input from user and then retrieve data.
Sample:
// Update the name of a customer, which is passed by user
// customerID passed by you to DB as integer value
// inputCustomerName passed by you to DB as string value
string commandText = "UPDATE Store SET CustomerName = @custName WHERE CustomerID = @ID;";

using (SqlConnection connection = new SqlConnection(connectionString))
{
        SqlCommand command = new SqlCommand(commandText, connection);
        command.Parameters.Add("@ID", SqlDbType.Int);
        command.Parameters["@ID"].Value = customerID;

        // Use AddWithValue to assign customer name.
        command.Parameters.AddWithValue("@custName", inputCustomerName);

        try
        {
            connection.Open();
            Int32 rowsAffected = command.ExecuteNonQuery();
            Console.WriteLine("RowsAffected: {0}", rowsAffected);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
}


在此处查找参数化查询及其用法:
MSDN:配置参数和参数数据类型(ADO.NET) [ MSDN:DataAdapter参数(ADO.NET) [ MSDN:SqlCommand.Parameters属性 [


Look here for parameterized query and it''s usage:
MSDN: Configuring Parameters and Parameter Data Types (ADO.NET)[^]
MSDN: DataAdapter Parameters (ADO.NET)[^]
MSDN: SqlCommand.Parameters Property [^]


从您的评论看来,您想知道如何编写存储过程.
http://msdn.microsoft.com/en-us/library/ms345415.aspx [ ^ ]
From your comments it sound like you want to know how to write a stored procedure.
http://msdn.microsoft.com/en-us/library/ms345415.aspx[^]


这篇关于如何在SQL Server 2005的pl/sql中接受用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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