Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please provide the steps to load the text boxes on the form with the details of the

first record out of the search.


stored procedure

SQL
ALTER PROCEDURE [dbo].[sp_SearchActLoan]
(
	@searchString	varchar(500)
)
AS
BEGIN
	
	IF @searchString <> ''
	BEGIN
		CREATE TABLE #SearchResults
		(
			Zidno   	varchar(20),
			Zid_Code   	varchar(20),
			Zapprs_No  	varchar(20),
			ZCustomer  	varchar(60),	
			Zint_No		varchar(10),
			Zint_Name	varchar(50),
			Zloanumber varchar (20)
			)

		Insert Into #SearchResults(Zidno,Zid_Code,Zapprs_No,ZCustomer,Zint_No,Zint_Name,Zloanumber)
		Select Distinct IDNO,ID_CODE,APPRS_NO,CUSTOMER,INT_NO,INT_NAME,LOANUMBER From LOANS
		Where IDNO Like '%' + @searchString + '%'
		Union
		Select Distinct IDNO,ID_CODE,APPRS_NO,CUSTOMER,INT_NO,INT_NAME,LOANUMBER From LOANS
		Where ID_CODE Like '%' + @searchString + '%'
		Union
		Select Distinct IDNO,ID_CODE,APPRS_NO,CUSTOMER,INT_NO,INT_NAME,LOANUMBER From LOANS
		Where APPRS_NO Like '%' + @searchString + '%'
		Union
		Select Distinct IDNO,ID_CODE,APPRS_NO,CUSTOMER,INT_NO,INT_NAME,LOANUMBER From LOANS
		Where CUSTOMER Like '%' + @searchString + '%'
		
														
		Select Zidno     'ACTUAL LOAN ID'  ,
		       Zid_Code  'CUSTOMER ID'  ,
		       Zapprs_No 'APPRAISAL NO',
		       ZCustomer 'NAME',
		       Zint_No   'INT_CODE',
		       Zint_Name 'INT_NAME',
		       Zloanumber 'LOANUMBER' 
		From #SearchResults order by Zidno,Zloanumber
	END



There are more controls on the form than the feeder into the grid

Please provide the necessary codes to populate the form with all the fields necessary to complete the form.

I am only able to get the output from the grid only on selection.

So after a search the form is not updated with the output in the grid.

Thanks

Added code from replies:
C#
public void LoadSearch()
        {


            try
            {
                SqlConnection connect = new SqlConnection();
                connect.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
                connect.Open();



                SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM LOANS order by LOANUMBER, IDNO", connect);

                SqlCommand SqlCmd = new SqlCommand("sp_searchActLoan", connect);
                SqlCmd.CommandType = CommandType.StoredProcedure;

                SqlCmd.Parameters.AddWithValue("@searchString", txt_Search.Text);
                SqlCmd.ExecuteNonQuery();

                // GridView1.DataSourceID = null;

                SqlDataAdapter daa = new SqlDataAdapter();
                daa.SelectCommand = SqlCmd;

                DataSet dsas = new DataSet();
                daa.Fill(dsas, "searchResults");
                // GridView1.DataSource = dsas;
                //GridView1.DataSourceID = null;
               

                GridView1.DataSource = dsas;
                GridView1.DataBind();
                
                connect.Close();

                GridView1.Visible = true;
                //GridView1.DataSource = dt;
                //GridView1.DataBind();
            }
            catch (Exception ex)
            {
                lblStatus.Text = ex.Message;
            }

        }

  protected void btn_Go_Click(object sender, EventArgs e)
        {
            if (txt_Search.Text != "")
                LoadSearch();

        }
Posted
Updated 26-Jan-15 12:33pm
v4
Comments
ZurdoDev 26-Jan-15 13:47pm    
Many different ways to do it. Where are you stuck?
Member 10744248 26-Jan-15 14:07pm    
After the stored procedure is invoked and the results are returned to the grid the form is not automatically updated.

How do I code the parameters for the return. which will populate the form
John C Rayan 26-Jan-15 16:29pm    
Please show us some sample code. How do you invoke the stored procedure and read the resultset in your code?
Member 10744248 26-Jan-15 17:29pm    
-- Added to question
Member 10744248 26-Jan-15 17:32pm    
-- Added to question

1 solution

First of all no need to open and close the connection, when you are using SqlDataAdapter.

Next, after filling the DataSet, all the data selected will be in one one Tables inside the DataSet. So, you need to access like dsas.Tables[0];. 0 is the first table of the selection you are making from the query.

Then after reading particular tables, just get their row and columns necessary and populate on the form fields.
 
Share this answer
 
Comments
Member 10744248 27-Jan-15 2:53am    
I tried that but I didnt get it before posting the question.

As a matter of fact the the page load has the same format.
Did you debug? What is the exact issue with that approach?

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