如何通过单击按钮从数据网格视图中检索数据 [英] how to retrieve data from data grid view by clicking on button

查看:69
本文介绍了如何通过单击按钮从数据网格视图中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GUI窗体.我想使用一个按钮通过数据网格视图显示数据库中的表.该按钮的名称为display,我想当我单击此显示按钮时整个表将通过数据网格视图.
我为此应用了以下编码,但在
上发生了错误 if(e.Keychar ==(char)13并且错误是:-

``System.EventArgs''不包含``Keychar''的定义,并且找不到扩展方法``Keychar''接受类型为``System.EventArgs''的第一个参数(您是否缺少using指令或装配参考?).




私有无效btndisplay_Click(对象发送者,EventArgs e)
{
if(e.Keychar ==(char)13) {
字符串strSQLconnection =数据源= AKMINDER-PC \ SQLEXPRESS;初始目录= ELIN设备(PHILIPS的联合制造商);集成安全性= True";
SqlConnection sqlConnection =新的SqlConnection(strSQLconnection);
SqlCommand sqlCommand =新的SqlCommand("SELECT * FROM vendor_info",sqlConnection);
sqlConnection.Open();

SqlDataReader reader = sqlCommand.ExecuteReader();

GridView1.DataSource =阅读器;
GridView1.DataBind();
GridView1.Visible = true;
GridView1.Focus();
}

I am working on GUI form .I want to use a button to display a table which is in database through data grid view.The button name is display and i want when i click on this display button the whole table will appear through data grid view.
I applied the below coding for that but error occured on
if (e.Keychar == (char)13 and the error is:-

''System.EventArgs'' does not contain a definition for ''Keychar'' and no extension method ''Keychar'' accepting a first argument of type ''System.EventArgs'' could be found (are you missing a using directive or an assembly reference?).




private void btndisplay_Click(object sender, EventArgs e)
{
if (e.Keychar == (char)13) {
string strSQLconnection = "Data Source=AKMINDER-PC\SQLEXPRESS;Initial Catalog=elin appliances(Comaker of PHILIPS);Integrated Security=True";
SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
SqlCommand sqlCommand = new SqlCommand("SELECT * FROM vendor_info", sqlConnection);
sqlConnection.Open();

SqlDataReader reader = sqlCommand.ExecuteReader();

GridView1.DataSource = reader;
GridView1.DataBind();
GridView1.Visible = true;
GridView1.Focus();
}

推荐答案

尝试使用:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode.ToString() == "Return")
    {
        //write here what you want
    }
}


将其置于键盘按下事件中,这是在按下Enter键的情况下


Put it in key down event,This is in case of Enter key pressed


这篇关于如何通过单击按钮从数据网格视图中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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