如何在单击特定的单元格时使用datagrid在相应的组合框中显示值 [英] how to use datagrid for displaying the values in respective combo boxes on clicking particular cell

查看:59
本文介绍了如何在单击特定的单元格时使用datagrid在相应的组合框中显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#.NET和SQL SERVER制作桌面应用程序
我已经创建了具有2个标签(潜在客户ID和潜在客户名称)的表格,分别带有组合框和使用过的datagrid视图...我希望数据应该显示在各个文本框中.我尝试了以下代码,但我没有得到显示的数据gor潜在客户名称

I am making desktop application using C#.NET and SQL SERVER
I have created form having 2 labels (prospect id and prospect name)with respective comboboxes and used datagrid view...I want that data should be displayed in respective textboxes.I have tried following code but i am not getting data displayed gor prospect_name

SqlConnection con = new SqlConnection("Data Source=SW-PC-20;Initial Catalog=PSM;Integrated Security=True");
            con.Open();

            SqlCommand com = new SqlCommand("select Prospect_ID,Prospect_Name from Filter where Prospect_ID=''" + dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() + "''", con);
            SqlDataReader dr = com.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                cboprospectid.Text = dr[0].ToString();
                cboprospectname.Text = dr[1].ToString();
            }
            dr.Close();
            con.Close();


现在的问题是,未为相应的潜在客户ID显示潜在客户名称.


Now problem is prospect name is not displayed for respective prospect id

推荐答案

您需要阅读有关如何使用ADO.NET的信息.在此处阅读有关ADO.NET的信息,它将对您有所帮助.

看看这些:
MSDN:ADO.NET [ MSDN:使用ADO.NET访问数据 [ ^ ]

C#Station ADO.NET教程 [为初学者使用ADO.NET [
You need to read on how to use ADO.NET. Read about ADO.NET here and it will help you.

Look at these:
MSDN: ADO.NET[^]
MSDN: Accessing Data with ADO.NET[^]

The C# Station ADO.NET Tutorial[^]
Using ADO.NET for beginners[^]


这篇关于如何在单击特定的单元格时使用datagrid在相应的组合框中显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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