增量搜索的输出问题 [英] Problem with output from Incremental Search

查看:70
本文介绍了增量搜索的输出问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在增量搜索后获取gridview上的输出错误VS 2010



围绕以下代码遇到困难





 SqlDataAdapter da =  new  SqlDataAdapter( @ 从Loanmaster中选择*,其中Id_Code LIKE @searchkey或Customer LIKE @searchkey 
或Apprs_No LIKE @searchkey
,sqlCon);



错误发生在,sqlcon

完整的代码如下:

  protected   void  btn_Incremental_Click(对象发​​件人,EventArgs e)
{


尝试
{
// 与数据库的连接

string str;
str = ConfigurationManager.ConnectionStrings [ ApplicationServices]。ConnectionString;
SqlConnection sqlCon = new SqlConnection(str);

// 调用语句

SqlCommand SqlCmd = new SqlCommand( @ 从Loanmaster中选择* Id_Code LIKE @searchkey或
Customer LIKE @searchkey或
Apprs_No LIKE @searchkey
,sqlCon);



SqlCmd.Parameters.AddWithValue( @ searchkey + txt_Search.Text + );

// 打开sql数据连接
sqlCon.Open ();

// 执行程序
SqlCmd.ExecuteNonQuery() ;

// 显示确认消息
lblstatus.Text = < span class =code-string> 搜索结果字符串: + txt_Search + 成功;


txt_Acct1.Text = ;
txt_Acct2.Text = ;
txt_Acct3.Text = ;



SqlDataAdapter da = new SqlDataAdapter( @ 从Loanmaster中选择*,其中Id_Code LIKE @searchkey或
Customer LIKE @searchkey或
Apprs_No LIKE @searchkey
,sqlCon);




DataSet ds = new DataSet();
da.Fill(ds, MLOANJOIN);

GridView1.DataSourceID = SqlDataSource1;
GridView1.DataBind();


txt_Acct1.Text = ds.Tables [ MLOANJOIN]。行[ 0 ] [ ACCT_NUMBER1< /跨度>]的ToString();
txt_Acct2.Text = ds.Tables [ MLOANJOIN]。行[ 0 ] [ ACCT_NUMBER2]。ToString() ;
txt_Acct3.Text = ds.Tables [ MLOANJOIN]。行[ 0 ] [ ACCT_NUMBER3]。ToString() ;



lblstatus.Text = 首次成功记录< /跨度>;
sqlCon.Close();
GridView1.SelectedIndexChanged + = new EventHandler(GridView1_SelectedIndexChanged);
txt_Id_Code.Enabled = false ;
txt_Appraisal.Enabled = false ;
txt_Customer.Focus();


sqlCon.Close();

}
catch (例外情况)
{
lblstatus.Text = ex.Message;
}



请协助



谢谢

解决方案

Having error getting the output on a gridview after an incremental search VS 2010

Having difficulty around the following codes


SqlDataAdapter da = new SqlDataAdapter(@"Select * from Loanmaster where Id_Code  LIKE @searchkey       or   Customer LIKE @searchkey
or   Apprs_No LIKE @searchkey", sqlCon);


The error is on ,sqlcon
THE FULL CODES ARE AS FOLLOWS::

protected void btn_Incremental_Click(object sender, EventArgs e)
{


    try
    {
        // Connection to the database
      
        string str;
        str = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
        SqlConnection sqlCon = new SqlConnection(str);

        //Call the statement 

       SqlCommand SqlCmd = new SqlCommand(@"Select * from Loanmaster where Id_Code  LIKE @searchkey or
                                                                           Customer LIKE @searchkey or
                                                                           Apprs_No LIKE @searchkey", sqlCon);


                                
       SqlCmd.Parameters.AddWithValue("@searchkey", "%" + txt_Search.Text +"%");

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

        //Execute the program
        SqlCmd.ExecuteNonQuery();

        //Display confirmation message
        lblstatus.Text = "Search Result with string : " + txt_Search + "was sucessful";


           txt_Acct1.Text = "";
           txt_Acct2.Text = "";
           txt_Acct3.Text = "";
 


           SqlDataAdapter da = new SqlDataAdapter(@"Select * from Loanmaster where Id_Code  LIKE @searchkey or
                                                                           Customer LIKE @searchkey or
                                                                            Apprs_No LIKE @searchkey", sqlCon);



        
        DataSet ds = new DataSet();
        da.Fill(ds, "MLOANJOIN");

        GridView1.DataSourceID = "SqlDataSource1";
        GridView1.DataBind();


        txt_Acct1.Text = ds.Tables["MLOANJOIN"].Rows[0]["ACCT_NUMBER1"].ToString();
        txt_Acct2.Text = ds.Tables["MLOANJOIN"].Rows[0]["ACCT_NUMBER2"].ToString();
        txt_Acct3.Text = ds.Tables["MLOANJOIN"].Rows[0]["ACCT_NUMBER3"].ToString();
       


        lblstatus.Text = "First record successful";
        sqlCon.Close();
        GridView1.SelectedIndexChanged += new EventHandler(GridView1_SelectedIndexChanged);
        txt_Id_Code.Enabled = false;
        txt_Appraisal.Enabled = false;
        txt_Customer.Focus();


        sqlCon.Close();

    }
    catch (Exception ex)
    {
        lblstatus.Text = ex.Message;
    }


Please assist

Thanks

解决方案

这篇关于增量搜索的输出问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆