Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following codes which have to fill the text boxes on the form however only one text box
is filled on pressing the select button.


C#
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
   //txtSave.Enabled = false;
   try
   {
      //connection to the database
      //
      //
      string str;
      str = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
      SqlConnection sqlcon = new SqlConnection(str);

      string intno;

      //Get the intno
      intno = GridView1.SelectedRow.Cells[1].Text;

      //call the stored procedure
      SqlCommand SqlCmd = new SqlCommand("sp_Getloanid", sqlcon);
      SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;

      //Supply the User_id parameter
      SqlCmd.Parameters.AddWithValue("@INTNO", intno);

      //Create and supply the output parameters

      SqlCmd.Parameters.Add("@INTNAME", System.Data.SqlDbType.VarChar, 50);
      SqlCmd.Parameters["@INTNAME"].Direction = System.Data.ParameterDirection.Output;

      SqlCmd.Parameters.Add("@CONTACT", System.Data.SqlDbType.VarChar, 50);
      SqlCmd.Parameters["@CONTACT"].Direction = System.Data.ParameterDirection.Output;

      SqlCmd.Parameters.Add("@INTSHORTCODE", System.Data.SqlDbType.VarChar, 50);
      SqlCmd.Parameters["@INTSHORTCODE"].Direction = System.Data.ParameterDirection.Output;
                            
      SqlCmd.Parameters.Add("@INTDATE", System.Data.SqlDbType.DateTime, 15);
      SqlCmd.Parameters["@INTDATE"].Direction = System.Data.ParameterDirection.Output;

      SqlCmd.Parameters.Add("@INTRATE", System.Data.SqlDbType.VarChar, 50);
      SqlCmd.Parameters["@INTRATE"].Direction = System.Data.ParameterDirection.Output;

      //Open the sql data connection
      sqlcon.Open();

      //Execute the stored procedures
      SqlCmd.ExecuteNonQuery();

      //Assign the results to the controls
      txt_Int_Code.Text = SqlCmd.Parameters["@INTNO"].Value.ToString();
      txt_Int_Name.Text = SqlCmd.Parameters["@INTNAME"].Value.ToString();
      txt_Short_Name.Text = SqlCmd.Parameters["@INTSHORTCODE"].Value.ToString();
      txt_contact.Text = SqlCmd.Parameters["@CONTACT"].Value.ToString();
      txt_Int_Dates.Text = SqlCmd.Parameters["@INTDATE"].Value.ToString();
      txt_Rates.Text = SqlCmd.Parameters["@INTRATE"].Value.ToString();
              
      lblstatus.Text = "Grid record successful";
      //
      //
      sqlcon.Close();
   }
   catch (Exception ex)
   {
      lblstatus.Text = ex.Message;
   }
}


**************************************************
store procedure
**************************************************

SQL
USE [Credit_App]
GO
/****** Object:  StoredProcedure [dbo].[sp_Get_Loanid]    Script Date: 05/26/2014 11:34:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter Procedure [dbo].[sp_Getloanid]
(
   @IntNo	varchar(20),
   @IntName	varchar(50) output ,
   @Contact	varchar(50) output ,
   @IntShortCode	varchar(10)output ,
   @IntDate	DateTime output,
   @IntRate	money output
)
AS
Begin
   Begin
      Update INTEREST
      Set INT_NAME = @IntName,INT_SHORT = @IntShortCode,INT_DATE = @IntDate,RATES = @IntRate, INT_CONTACT=@Contact
      Where INT_NO = @IntNo
   End
End


***************************************

Please assist to get the text boxes filled

Thanks

[Agent_Spock]
- added code brackets
indentation and correct languages
Posted
Updated 26-May-14 8:58am
v3
Comments
gggustafson 26-May-14 12:22pm    
Haven't you reversed the variables in the Set statement? Like shouldn't "Set INT_NAME = @IntName" be "Set @IntName = INT_NAME"?
Member 10744248 27-May-14 9:06am    
Thanks it worked

1 solution

That is because you are not assigning any values to the parameter inside the Stored Procedure.

As those are Output Parameters, so you should assign something to them in order to get their value.
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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