Gridcellselect不执行任何操作

Gridcellselect不执行任何操作

本文介绍了代码中有什么问题.... Gridcellselect不执行任何操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了存储过程HSNMasterView来从表中选择值



我写了FillDataGridView函数填充datagridview并在SearchClick中调用此函数



我尝试过:



I have written the Stored procedure "HSNMasterView" for select the value from table

I have written the FillDataGridView function fill the datagridview and call this function in SearchClick

What I have tried:

// dbo.HSNMasterView
ALTER PROCEDURE dbo.HSNMasterView
@HSNCode int AS SELECT * FROM inv_hsn WHERE  status = 1




//FillDataGridView
private void FillDataGridView()
        {
            try
            {
                if (sqlcon.State == ConnectionState.Closed)
                    sqlcon.Open();
                SqlDataAdapter sqlda = new SqlDataAdapter("HSNMasterView", sqlcon);
                sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
sqlda.SelectCommand.Parameters.AddWithValue("@HSNCode",txt_HSNSearch.Text.Trim());
                DataTable dtbl = new DataTable();
                sqlda.Fill(dtbl);
                dgv_HSNMaster.DataSource = dtbl;
                dgv_HSNMaster.Columns[0].Visible = false;
                sqlcon.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

//Search Code
private void dgv_HSNMaster_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                FillDataGridView();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }

推荐答案

sqlda.SelectCommand.Parameters.AddWithValue("@HSNCode",int.parse(txt_HSNSearch.Text.Trim()));



2.有一个搜索按钮(如果你已经拥有它,则使用它)并在按钮点击事件中绑定gridview。



如果我的假设不正确,请告诉我。你的问题不是这个。



希望,它有帮助:)


2. Have a search button(or use if you already have it) and bind the gridview in the button click event.

Please let me know if my assumptions are not correct and your problem is something other than this.

Hope, it helps :)


这篇关于代码中有什么问题.... Gridcellselect不执行任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 22:44