ado.net问题陈述 [英] ado.net Problem Statement

查看:66
本文介绍了ado.net问题陈述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑需要创建窗体以显示记录值等于750的产品记录器数据的示例。通过在DbCommand对象的帮助下将SQL命令发送到数据库来获取数据。

Consider example where a windows form need to be created to display the product recorder data having record value equal to 750.The data will be fetched by sending SQL command to the database with the help of DbCommand object.

推荐答案

ADO.Net简介:教程 [ ^ ]。

最佳起点你正在学习新东西是一个简单的教程。通过在google的搜索栏中键入几个主要主题,几乎总能找到这些内容。
Introduction to ADO.Net: Tutorial[^].
The best place to start when you are learning something new is a simple tutorial. These can almost always be found very quickly by typing a couple of your primary subjects into the search bar in google.


假设您的Sql连接已经创建,还有您的sql命令。可以调用此代码;你传递sql命令和你的连接变量,它会返回一个数据表给你处理并显示在你的表格中。



Assuming that your Sql connection is already created and also your sql command. This code can be called; you pass you sql command and your connection variable to it, it will return a datatable back to you to process and display in your form.

public DataTable ProcessCommand(string sql, SqlConnection conn)
       {
           SqlCommand _MiscCommand = default(SqlCommand);
           if (conn.State == ConnectionState.Closed)
           {
               conn.Open();
           }
           try
           {
               _MiscCommand = new SqlCommand(sql, conn);
               DataSet rsMiscAdapter = new SqlDataAdapter(_MiscCommand);
               DataTable table = new DataTable();
               rsMiscAdapter.Fill(table);
               return table;
           }
           catch (Exception )
           {
               return null;
           }
       }


这篇关于ado.net问题陈述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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