使用搜索和gridview中的第一条记录加载表单 [英] Load the form with the first record from a search and gridview
本文介绍了使用搜索和gridview中的第一条记录加载表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请提供以下步骤:在表单上加载文本框,并附上搜索结果中第一条记录的详细信息。
存储过程
ALTER PROCEDURE [dbo]。[sp_SearchActLoan]
(
@ searchString varchar ( 500 )
)
AS
BEGIN
IF @ searchString <> ' '
BEGIN
CREATE TABLE #SearchResults
(
Zidno varchar ( 20 ),
Zid_Code varchar (< span class =code-digit> 20 ),
Zapprs_No varchar ( 20 ),
ZCustomer varchar ( 60 ),
Zint_No varchar ( 10 ),
Zint_Name varchar ( 50 ),
Zloanumber varchar ( 20 )
)
插入 进入 #SearchResults(Zidno,Zid_Code,Zapprs_No,ZCustomer,Zint_No,Zint_Name,Zloanumber)
选择 Distinct IDNO,ID_CODE,APPRS_NO,CUSTOMER,INT_NO,INT_NAME,LOANUMBER 来自 LOANS
其中 IDNO 赞 ' %' + @ searchString + ' %'
联盟
选择 区别 IDNO,ID_CODE,APPRS_NO,CUSTOMER,INT_NO,INT_NAME,LOANUMBER 来自 LOANS
其中 ID_CODE 赞 ' %' + @ searchString + ' %'
联盟
选择 不同 IDNO,ID_CODE,APPRS_NO, CUSTOMER,INT_NO,INT_NAME,LOANUMBER From LOANS
其中 APPRS_NO 喜欢 ' %' + @searchString + ' %'
联盟
选择 不同 IDNO,ID_CODE,APPRS_NO,CUSTOMER,INT_NO ,INT_NAME,LOANUMBER 来自 LOANS
其中 CUSTOMER 喜欢 ' %' + @ searchString + ' %'
选择 Zidno ' ACTUAL LOAN ID',
Zid_Code ' < span class =code-string> CUSTOMER ID',
Zapprs_No ' APPRAISAL NO' ,
ZCustomer ' NAME',
Zint_No ' INT_CODE',
Zint_Name ' < span class =code-string> INT_NAME',
Zloanumber ' LOANUMBER'
来自 #SearchResults order by Zidno,Zloanumber
END
表单上的控件比进入网格的进纸器更多/>
请提供必要的代码填写表格,填写表格所需的所有字段。
I我只能在选择时从网格中获得输出。
因此在搜索后,表格不会更新网格中的输出。
谢谢
从回复中添加代码:
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 (例外情况)
{
lblStatus.Text = ex.Message;
}
}
受保护 void btn_Go_Click( object sender,EventArgs e)
{
if (txt_Search .Text!= )
LoadSearch();
}
解决方案
首先,当您使用时,无需打开和关闭连接SqlDataAdapter
。
接下来,在填充DataSet之后,所选的所有数据都将在一个DataSet内的表中。因此,您需要访问dsas.Tables [0];
。 0是您从查询中选择的第一个表格。
然后在阅读特定表格后,只需获取其行和列并填写表单字段
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
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:
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();
}
解决方案
First of all no need to open and close the connection, when you are usingSqlDataAdapter
.
Next, after filling the DataSet, all the data selected will be in one one Tables inside the DataSet. So, you need to access likedsas.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.
这篇关于使用搜索和gridview中的第一条记录加载表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文