如何在数据库中隐藏详细信息我运行我的Windows窗体 [英] How Do I Hide Details In The Database Everytym I Run The My Windows Form

查看:121
本文介绍了如何在数据库中隐藏详细信息我运行我的Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视觉基本窗口窗体绑定到数据库(访问和sql)),当我运行它并输入数据时,它显示在数据网格视图和相关的标签和文本框中。 howeva我会lyk它执行,当我输入我的产品的i.d没有时,表单显示产品名称和价格,而不是每次运行它时都必须加载数据。我希望它在我输入i.d号后显示。 thankyou

i have my visual basic windows form which is binded to the database(access and sql)) and when i run it and input data it displays both in the datagrid view and the related labels and textboxes. howeva i would lyk it to perform whereby when i input the i.d no of my product, the form displays the product name and its price rather than having to load the data every time i run it. i would like it to display after i have put the i.d number. thankyou

推荐答案

因此删除DataGridView和相关的绑定。

您只需使用SqlConnection和SqlCommand(或者他们的用于访问的Odbc等价物:

So remove the DataGridView and the associated binding.
You can retrieve individual values just using an SqlConnection and an SqlCommand (or their Odbc equivalents for Access):
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("SELECT Id, description FROM myTable WHERE Id=@Id", con))
        {
        cmd.Parameters.AddWithValue("@ID", txtIDToLocate.Text);
        using (SqlDataReader reader = cmd.ExecuteReader())
            {
            if (reader.Read())
                {
                int id = (int) reader["Id"];
                string desc = (string) reader["description"];
                ...
                }
            }
        }
    }


这篇关于如何在数据库中隐藏详细信息我运行我的Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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