Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Store Procedure:
SQL
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# Code:
C#
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);
            }
}





Question:
Now how can i get the value of 'PINo' in TextBox?
Posted
Updated 23-Apr-14 21:16pm
v2

Try this:

C#
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);
}
}
 
Share this answer
 
Comments
Dew Drops 24-Apr-14 3:46am    
Thanks for your ans.I am trying in that way but txtPurInvNo.text is not supported .how can it support?
Tom Marvolo Riddle 24-Apr-14 3:55am    
Not Supported means?I didn't get it.Getting any errors?
Dew Drops 24-Apr-14 4:12am    
when i put txtPurInvNo.Text = dr[0].ToString(); then txtPurInvNo.Text shows in red mark and the error is "An object referecne is required for the non static field,method or property"
Tom Marvolo Riddle 24-Apr-14 4:52am    
Try: private void GetInvoice()
Dew Drops 25-Apr-14 23:36pm    
Thanks :)
pleace once textbox on form with TextBox1
 
Share this answer
 
Comments
Dew Drops 25-Apr-14 12:37pm    
sprry i don't understand about your talk.is it possible to give me an example?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900