如何在两个现有列的数据表中创建新列 [英] How to create a new column in a datatable from two existing column

查看:76
本文介绍了如何在两个现有列的数据表中创建新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两个现有列的数据表中创建一个新列。我使用datatable.columns.add

方法创建新列没有问题
。问题是新列的值可能变成system.dbnull

,因为两个现有列中的一个可能有system.dbnull。我如何修复

它以便新列将获得另一列的值,即使是另一列

列是system.dbnull?

I want to create a new column in a datatable from two existing columns. I
have no problem to create the new column using the datatable.columns.add
method. The problem is the value of the new column may become system.dbnull
since one of the two existing columns may have system.dbnull. How can I fix
it so the new column will get the value of the other column even the other
column is system.dbnull?

推荐答案

假设您正在使用SELECT语句来获取数据,您可以将

组合在语句中的字段中,SQL将会处理字符串中的任何空单元格

类型列为空字符串...


SELECT FirstName& " " &安培;来自客户的LastName AS CustomerName ...

在此示例中,如果FirstName为null并且只有

给定记录的姓氏,则CustomerName将仅显示为姓氏。您将
将您的网格列映射到CustomerName。此外,此示例假定

列都是字符串。您还可以在SQL中组合数字列,但使用+

而不是&。

" Peter"写道:
Assuming you are using a SELECT statement to get your data, you can combine
the fields in the statement, and SQL will treat any null cells from a string
type column as empty strings...

SELECT FirstName & " " & LastName AS CustomerName FROM Customers...

In this example, if a FirstName is null and there is only a last name for a
given record, the CustomerName would be shown as only the last name. You
would map your grid column to CustomerName. Also, this example assumes both
columns are strings. You can also combine numeric columns in SQL, but use +
rather than &.
"Peter" wrote:

我想在两个现有列的数据表中创建一个新列。我使用datatable.columns.add

方法创建新列没有问题
。问题是新列的值可能变成system.dbnull

,因为两个现有列中的一个可能有system.dbnull。如何修复

它以便新列将获得另一列的值,即使是另一列

列是system.dbnull?
I want to create a new column in a datatable from two existing columns. I
have no problem to create the new column using the datatable.columns.add
method. The problem is the value of the new column may become system.dbnull
since one of the two existing columns may have system.dbnull. How can I fix
it so the new column will get the value of the other column even the other
column is system.dbnull?


你好查理,


数据表是从.NET方法返回的,所以我无法控制

SELECT语句。


" Charlie"写道:
Hi Charlie,

The datatable is returned from a .NET method so I have no control on the
SELECT statement.

"Charlie" wrote:

假设您使用SELECT语句来获取数据,您可以将

组合在语句中的字段中,SQL将将字符串

类型列中的任何空单元格视为空字符串...


SELECT FirstName& " " &安培;来自客户的LastName AS CustomerName ...

在此示例中,如果FirstName为null并且只有

给定记录的姓氏,则CustomerName将仅显示为姓氏。您将
将您的网格列映射到CustomerName。此外,此示例假定

列都是字符串。您还可以在SQL中组合数字列,但使用+

而不是&。


" Peter"写道:
Assuming you are using a SELECT statement to get your data, you can combine
the fields in the statement, and SQL will treat any null cells from a string
type column as empty strings...

SELECT FirstName & " " & LastName AS CustomerName FROM Customers...

In this example, if a FirstName is null and there is only a last name for a
given record, the CustomerName would be shown as only the last name. You
would map your grid column to CustomerName. Also, this example assumes both
columns are strings. You can also combine numeric columns in SQL, but use +
rather than &.
"Peter" wrote:

我想在两个现有列的数据表中创建一个新列。我使用datatable.columns.add

方法创建新列没有问题
。问题是新列的值可能变成system.dbnull

,因为两个现有列中的一个可能有system.dbnull。我如何修复

它以便新列将获得另一列的值,即使是另一列

列是system.dbnull?

I want to create a new column in a datatable from two existing columns. I
have no problem to create the new column using the datatable.columns.add
method. The problem is the value of the new column may become system.dbnull
since one of the two existing columns may have system.dbnull. How can I fix
it so the new column will get the value of the other column even the other
column is system.dbnull?


我不知道你指的是哪种.net方法,但是你仍然应该能够控制你的b $ b SELECT语句。 DataAdapter将是用于从Access或SQL数据库获取数据的最常用的
常见.net对象。

SELECT语句是该对象的属性,可以作为

参数传递,也可以设置为属性。


在任何情况下,只要您使用运行sql语句的数据库,

就应该能够以允许您使用SELECT语句的方式重新编码。


" Peter"写道:
I don''t know which .net method you are referring to, but you should still be
able to control the SELECT statement. The DataAdapter would be the most
common .net object to use to get data from an Access or SQL database. The
SELECT statement is a property of that object and can be passed as a
parameter, or set as a property.

In any case, as long as you are using a database that runs sql statements,
you should be able to re-code in a way that lets you use a SELECT statement.

"Peter" wrote:

你好查理,


数据表是从.NET方法返回的,所以我无法控制

SELECT语句。


" Charlie"写道:
Hi Charlie,

The datatable is returned from a .NET method so I have no control on the
SELECT statement.

"Charlie" wrote:

假设您使用SELECT语句来获取数据,您可以将

组合在语句中的字段中,SQL将将字符串

类型列中的任何空单元格视为空字符串...


SELECT FirstName& " " &安培;来自客户的LastName AS CustomerName ...

在此示例中,如果FirstName为null并且只有

给定记录的姓氏,则CustomerName将仅显示为姓氏。您将
将您的网格列映射到CustomerName。此外,此示例假定

列都是字符串。您还可以在SQL中组合数字列,但使用+

而不是&。

" Peter"写道:
Assuming you are using a SELECT statement to get your data, you can combine
the fields in the statement, and SQL will treat any null cells from a string
type column as empty strings...

SELECT FirstName & " " & LastName AS CustomerName FROM Customers...

In this example, if a FirstName is null and there is only a last name for a
given record, the CustomerName would be shown as only the last name. You
would map your grid column to CustomerName. Also, this example assumes both
columns are strings. You can also combine numeric columns in SQL, but use +
rather than &.
"Peter" wrote:

我想在两个现有列的数据表中创建一个新列。我使用datatable.columns.add

方法创建新列没有问题
。问题是新列的值可能变成system.dbnull

,因为两个现有列中的一个可能有system.dbnull。我如何修复

它以便新列将获得另一列的值,即使是另一列

列是system.dbnull?

>

>

>
I want to create a new column in a datatable from two existing columns. I
have no problem to create the new column using the datatable.columns.add
method. The problem is the value of the new column may become system.dbnull
since one of the two existing columns may have system.dbnull. How can I fix
it so the new column will get the value of the other column even the other
column is system.dbnull?
>
>
>


这篇关于如何在两个现有列的数据表中创建新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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