如何在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