使用C#和VS2010将文件移到Windows屏幕 [英] Moving fileds to windows screen using C# and VS2010

查看:50
本文介绍了使用C#和VS2010将文件移到Windows屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将字段从表移动到Windows屏幕.我正在使用C#,VS2010,它是Windows应用程序:

这是我用来检索字段的代码:

I am trying to move fields from a table to a Windows screen. I am using C#, VS2010, and it''s a windows application:

This is the code I use to retreive fields:

cmd.CommandText = "SELECT COUNT(DIS_NO) FROM BM_DISPUTES";
cmd.CommandText = "SELECT * FROM BM_DISPUTES WHERE " +
                  "DIS_NO = CONVERT(int," + clientID.Text + ")";


这是我要转到屏幕上的内容:


This what I am trying to move to screen:

fname.Text = ("DIS_FIRSTNAME"); =(field names)
lname.Text = ("DIS_LASTNAME");  =(field names)


我正在尝试做一些非常简单的事情,并且我所看到的所有示例实际上都使用了提供的文字.请帮忙.只是学习...

Ben


I am trying to do something very simple and all the samples I have seen are actually using literals that are supplied. Please Help. Just learning...

Ben

推荐答案

您检查过的任何示例是否使用了DataTable或SqlDatReader?

Have any of the samples you have reviewed used a DataTable or SqlDatReader?

using(SqlCommand cmd = new SqlCommand("command text", conn))
{
   conn.Open();
   
   DataTable dt = new DataTable();
   dt.Load(cmd.ExecuteReader());

   fname.Text = dt.Rows[0]["field name"];

   or

   SqlDataReader reader = cmd.ExecuteReader();
   while(reader.Read())
   {
     fname.Text = reader.GetString(ordinal number);
   }
}


如解决方案1中所指出的,您可以使用数字获得f字段值.但是,如果对字段进行了任何更改(例如订购或添加字段),那么您将不会知道代码已损坏.使用存储的过程与SQL数据库进行交互被认为是更可取的.顺序更改或添加/删除字段可能会造成严重破坏.同样,使用序数将很难调试.这就是为什么您通常会看到字段名称以字符串形式传递的原因.
As pointed out in solution 1 you can get f field value by using a number. However, if there are ever any changes to the fields (such as order, or add a field), then you will not know that your code is broken. It is considered preferable to interface with a SQL database using stored proceedures. The change in order or adding/deleting fields can cause havoc. Also, using an ordinal would be much harder to debug. This is why you normally see field names passed as strings.


这篇关于使用C#和VS2010将文件移到Windows屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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