如何在Asp.Net中使用存储过程在文本框中显示数据 [英] How Can I Display Data In Textbox Using Store Procedure In Asp.Net
本文介绍了如何在Asp.Net中使用存储过程在文本框中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
存储过程:
Store Procedure:
ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create procedure [dbo].[GetPurchaseInvNo]
as
select max(cast(ISNULL(dbo.RemoveNonAlphaCharacters(PINo),0)+1 as bigint)) from dbo.T_PTransaction
C#代码:
C# Code:
private static void GetInvoice()
{
try
{
using (SqlConnection con = new SqlConnection(Class_Connection.ETConnection))
{
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetPurchaseInvNo";
cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
问题:
现在如何在TextBox中获取'PINo'的值?
Question:
Now how can i get the value of 'PINo' in TextBox?
推荐答案
试试这个:
Try this:
private static void GetInvoice()
{
try
{
using (SqlConnection con = new SqlConnection(Class_Connection.ETConnection))
{
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetPurchaseInvNo";
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
TextBox1.Text= dr[0].ToString();
}
dr.Close();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
pleace一旦带有TextBox1的表单上的文本框
pleace once textbox on form with TextBox1
这篇关于如何在Asp.Net中使用存储过程在文本框中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文