如何使用存储过程计算将整数值插入到文本框中

本文关键字:插入 文本 整数 何使用 存储过程 计算 | 更新日期: 2023-09-27 18:23:47

我有一个存储过程,用于计算员工的pf,如下所示:

USE [test]
GO
CREATE PROCEDURE [dbo].[DA] 
AS
BEGIN
SELECT e.emp_id,
e.name,
p.salary,
p.category,
p.salary * 0.12 as da
from emp as e,
payroll as p where
e.emp_id = p.emp_id
END

当我们从下拉列表中选择不同的工资值时,我必须在C#的文本框中显示结果,即DA值。请帮我处理C#代码。

如何使用存储过程计算将整数值插入到文本框中

步骤1:

读取dataReader 中的数据

步骤2:

在读卡器的文本框中设置值。

步骤3:

在dropdwon更改事件中编写以下代码。。。。

Eample:

          // Open connection to the database
                string ConnectionString = "server=myserver;uid=sa;"+
                    "pwd=manager; database=northwind";
                con = new SqlConnection(ConnectionString);
                con.Open();
                // Set up a command with the given query and associate
                // this with the current connection.
                string CommandText = "DA";
                cmd = new SqlCommand(CommandText);
                cmd.Connection = con;
                storedProcCommand.CommandType = CommandType.StoredProcedure;

                // Execute the query
                rdr = cmd.ExecuteReader();
                while(rdr.Read())
                {
                    mytextbox.Text =rdr["da"].ToString() ;                
                 }