如何根据银行名称组合框中的选定值显示datagridview行中的检查详细信息 [英] How to show cheque details in datagridview row based on selected value from bank name combobox

查看:45
本文介绍了如何根据银行名称组合框中的选定值显示datagridview行中的检查详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表bankdetails和chequedetails表两个表都有bankid。我在bankid列上创建了foreignkey。我在两个表中都插入了一些记录。现在我有bankname combobox,accountno文本框和accounttype combobox.And datagridview.dridview是从chequedetails表填充。

现在如果我在banknamecombobox accountno中选择bankname并且帐户应该显示fine.Now我想要基于banknameselectedid显示datagridview中的相关行显示

来自chequedetails餐桌。

请帮帮我。

提前致谢。



我尝试过:



I have two tables bankdetails and chequedetails table both tables have bankid.I created foreignkey on bankid column.I inserted some records in both the tables.Now i have bankname combobox,accountno textbox and accounttype combobox.And one datagridview.dridview is populate from the chequedetails table.
Now if i select bankname in the banknamecombobox accountno and account should displaying fine.Now i want based on banknameselectedid show the related row show in the datagridview
which is coming from chequedetails table.
Please help me on this.
Thanks in advance.

What I have tried:

<pre>   private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
            string abc = comboBox1.SelectedValue.ToString();
            if (abc != "[select, select]" && abc != "select")
            {
                SqlConnection con = new SqlConnection(connection);
                con.Open();
                SqlCommand cmd = new SqlCommand("SELECT [bank_Id],
           [bank_Accountno],bank_Accountype FROM bankdetails where 
             bank_Id=@bank_Id",con);
                cmd.Parameters.AddWithValue("@bank_Id", 
                 comboBox1.SelectedValue.ToString());
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    txtAcntno.Text = dt.Rows[0]["bank_Accountno"].ToString();
                    cmbAcntype.Text = dt.Rows[0]["bank_Accountype"].ToString().Trim();
                    LoadDataGridView();
                }
            }
            else if (comboBox1.SelectedIndex == 0)
            {
                txtAcntno.Text = "";
                cmbAcntype.SelectedIndex = 0;
            }
        }










private void LoadDataGridView()
       {

       SqlConnection con = new SqlConnection(connection);
       SqlCommand cmd = new SqlCommand(" SELECT bank_Id,row_number() over(order by [bank_Id]) as SlNo,[bank_Chqstartno],[bank_Chqendno],case bank_Chqlvscount when 100 then 2 when 50 then 1 when 10 then 0 end as noofcheques ,bank_Chqlvscount,bank_Stat FROM [dbo].bankcheques where bank_Id=@bank_Id order by SlNo desc ", con);
       try
       {
           con.Open();
           SqlDataAdapter da = new SqlDataAdapter();
           da.SelectCommand = cmd;
           DataTable dt = new DataTable();
           da.Fill(dt);
           DataGridViewComboBoxColumn cmb = dgvwChqs.Columns["noofcheques"] as DataGridViewComboBoxColumn;
           cmb.DataSource = dt;
           cmb.DisplayMember = "bank_Chqlvscount";
           cmb.ValueMember = "bank_Id";
           cmb.HeaderText = "No. of Cheques";
           dgvwChqs.DataSource = dt;
           con.Close();
       }
       catch (Exception ex)
       {
           MessageBox.Show(ex.Message);
       }
   }

推荐答案

再次阅读你的问题我猜你真的将银行名称作为ComboBox中的选定值而不是bankid。



如果您有银行名称并希望根据该名称获得支票,那么您只需必须加入银行详细信息表...
Reading your question through again I'm guessing that you actually have the bank name as the selectedvalue in the ComboBox and not the bankid.

If you have the bank name and want to get the cheques based on that, then you just have to join to the bank details table ...
SELECT BC.bank_Id,row_number() over(order by [bank_Id]) as SlNo,[bank_Chqstartno],[bank_Chqendno],
	case bank_Chqlvscount when 100 then 2 when 50 then 1 when 10 then 0 end as noofcheques ,
	bank_Chqlvscount,bank_Stat 
FROM [dbo].bankcheques BC
INNER JOIN [dbo].bankdetails BD ON BC.bank_Id = BD.bank_Id
where bank_name=@bank_name 
order by SlNo desc 


这篇关于如何根据银行名称组合框中的选定值显示datagridview行中的检查详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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