Click here to Skip to main content
Sign Up to vote bad
good
can you show me .... how to display it from sql table
 
my stored procedure
 
ALTER PROCEDURE [dbo].[Transaction]  
( 
           
            @Patient nvarchar(50),
            @E_TO nvarchar(50),
            @R_type int,
            @User_name nvarchar(50),
            @ReportType nvarchar(50),
            @Patient_no  int,
            @Patient_ID_NO numeric(18,0),
            @idcount numeric(18,0) output
   
) 
AS  
BEGIN  
           
         declare @tempid numeric(18,0)
         set @tempid = 0;  
         declare @idcnt numeric(18,0)
         select @idcnt =isnull( max(idcount),0) from Transactions where year(R_date)=year(getdate())  
         if (@idcnt =0)  
         set @tempid=1  
         else  
         set @tempid = @idcnt +1  
        
          
          INSERT INTO dbo.Transactions (Patient,E_TO,R_date,R_from,User_name,report_type,Patient_no,Patient_ID_NO,idcount)values (@Patient,@E_TO,getdate(),@R_type,@User_name,@ReportType,@Patient_no,@Patient_ID_NO,@tempid)
return @idcount
 END 
my code
try
            {
                if (NameTxtBx.Text == "" || ToTxtBx0.Text == "" || DropDownList1.SelectedIndex == 0 || RadioButtonList2.SelectedIndex == -1 || ( PatID_NO.Text == "")|| (Convert.ToUInt64(PatNo.Text) <= 0) || (Convert.ToUInt64(PatNo.Text) > 200000000))
                {
                    Message("Please check the field u entered", this);
                    return;
                   
                }
                else
                {
                    try
                    {
                        
                    
                        string Patient_name = NameTxtBx.Text, Export_TO = ToTxtBx0.Text, repType = RadioButtonList2.SelectedValue  ;
                        int PatNoVal;
                        PatNoVal = Convert.ToInt32(PatNo.Text);
                        PatNoVal = int.Parse(PatNo.Text);
                        decimal PatID = decimal.Parse(PatID_NO.Text);
                        int? replay_To_type = Int16.Parse(DropDownList1.SelectedValue);
                        string idcount;
 
                        try
                        {
 
                            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
                            con.Open();
                            SqlCommand cmd = new SqlCommand();
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.CommandText = "Transaction";
                            cmd.Parameters.AddWithValue("@Patient", Patient_name);
                            cmd.Parameters.AddWithValue("@E_TO", Export_TO);
                            cmd.Parameters.AddWithValue("@R_type", repType);
                            cmd.Parameters.AddWithValue("@ReportType", replay_To_type);
                            cmd.Parameters.AddWithValue("@Patient_no", PatNoVal);
                            cmd.Parameters.AddWithValue("@Patient_ID_NO", PatID);
                            cmd.Parameters.AddWithValue("@User_name", Label1.Text = Session["name"].ToString ());
                            cmd.Parameters.Add("@idcount", SqlDbType.Decimal);
                            cmd.Parameters["@idcount"].Direction = ParameterDirection.Output;
                            cmd.Connection = con;
                            cmd.ExecuteNonQuery();
                            con.Close();
                            TextBox1.Text = cmd.Parameters["@RETURNOUT"].Value.ToString();
                            ClientScriptManager cs = Page.ClientScript;
                            cs.RegisterStartupScript(this.GetType(), "IDCount", "alert('" + cmd.Parameters["@RETURNOUT"].Value.ToString() + "');", true);
 
                        }
 
                        catch (Exception ex)
                        {
                            Message("Block 3: Error\nThe Reported fault is:\n" + ex.Message, this);
                        }
 
                        PatNo.Text = "";
Posted 1-Jul-12 1:35am
Edited 1-Jul-12 3:00am


2 solutions

try as below, you need to create sql connection by giving connection string.
and then you can create command by given your select query with where condition which match only the return out value of your insert method.
Add the parameter values, and Execute the Reader and you can get values by index as below.
 
SqlConnection Conn = new SqlConnection(Connection_String);
SqlCommand Comm1 = new SqlCommand(Command, Conn);
cmd.Parameters.AddWithValue("@Parametername", parameterValue);
Conn.Open();
SqlDataReader reader= Comm1.ExecuteReader();
if (reader.Read())
{
    textBox.Text = reader.GetValue(0).ToString();
}
Conn.Close();
  Permalink  
Comments
ooffooooo - 1-Jul-12 8:03am
can you edit my code with these lines????

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 6,824
1 Prasad_Kulkarni 3,671
2 _Amy 3,312
3 OriginalGriff 3,309
4 CPallini 2,925


Advertise | Privacy | Mobile
Web03 | 2.6.130617.1 | Last Updated 1 Jul 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid