使用存储过程的返回来填充文本框 [英] populating the text boxes with a return from a stored procedure
本文介绍了使用存储过程的返回来填充文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的专家
尝试通过加入3个字段来填充表单中的文本框。
但是我没有得到返回值。
Dear expert
Trying to populate text boxes in a form by joining 3 fields.
However I am not getting the return values.
//*************************************************
public void LoadEmployee()
{
string str;
str = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlConnection sqlcon = new SqlConnection(str);
if (sqlcon.State == ConnectionState.Open)
{
sqlcon.Close();
}
sqlcon.Open();
lblstatus.Text = "CONNECTED";
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
cmd.Connection = sqlcon;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GET_ALL_EMPLOYEE";
da.SelectCommand = cmd;
da.Fill(ds);
DataTable dt = new DataTable();
dt = ds.Tables[0];
txt_Empname.Items.Clear();
for (int i = 0; i < dt.Rows.Count; i++)
{
txt_Empname.Items.Add(dt.Rows[i]["STAFFNAME"].ToString());
}
txt_Empname.SelectedIndex = 0;
}
protected void txt_Empname_SelectedIndexChanged(object sender, EventArgs e)
{
Session["txt_Empname"] = txt_Empname.SelectedValue;
txt_Empname.SelectedIndex = txt_Empname.Items.IndexOf(txt_Empname.Items.FindByValue(Convert.ToString(Session["txt_Empname"])));
GetEmpDetails(Session["txt_Empname"].ToString());
}
public void GetEmpDetails(string PosCode)
{
string str;
str = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlConnection sqlcon = new SqlConnection(str);
if (sqlcon.State == ConnectionState.Open)
{
sqlcon.Close();
}
sqlcon.Open();
lblstatus.Text = "CONNECTED";
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
cmd.Connection = sqlcon;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GET_EMPDETAILS";
SqlParameter param1 = new SqlParameter();
param1.ParameterName = "STAFFNAME";
param1.Direction = ParameterDirection.Input;
param1.SqlDbType = SqlDbType.VarChar;
param1.Value = PosCode;
param1.Value = Session["txt_Empname"];
cmd.Parameters.Add(param1);
da.SelectCommand = cmd;
da.Fill(ds);
DataTable dt = ds.Tables[0];
txt_Empno.Text = dt.Rows[0]["EMPNO"].ToString();
txt_Dept_No.Text = dt.Rows[0]["DEPT_NO"].ToString();
txt_Dept_Name.Text = dt.Rows[0]["DEPT_MAME"].ToString();
txt_Br_No.Text = dt.Rows[0]["BRN_NO"].ToString();
txt_Brn_Name.Text = dt.Rows[0]["BRN_NAME"].ToString();
}
}
存储过程如下关注::
The stored procedures are as follows ::
ALTER PROCEDURE [dbo].[GET_ALL_EMPLOYEE]
AS
BEGIN
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT FNAME+' '+LNAME+' '+MID_NAME AS STAFFNAME,
EMPNO,BRANAME,BRANCH,DEPT,DEPTNAME
FROM PAYMAST ORDER BY FNAME
END
---------------------------------- -----------------------------
---------------------------------------------------------------
ALTER PROCEDURE [dbo].[GET_EMPDETAILS]
@STAFFNAME VARCHAR(50)
AS
BEGIN
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT EMPNO,BRANAME,BRANCH,DEPT,DEPTNAME
FROM PAYMAST
WHERE FNAME+' '+LNAME+' '+MID_NAME= @STAFFNAME
END
请协助
谢谢
Please assist
Thanks
推荐答案
最简单的解决方案是将过程转换为表函数。在这种情况下,您可以像代码中的表一样访问它们。如果要将它们保留为过程,则必须将所需的值声明为OUT参数(请参阅SQL文档,了解如何执行这两种解决方案)。
The simpliest solution would be to turn the procedures into table functions. In this case you can access them like tables from code. If you want to keep them as procedures, you'll have to declare the desired values as OUT parameters (see SQL documentation how to do both solutions).
这篇关于使用存储过程的返回来填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文