Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在VB.NET中使用ADO.NET将sql Server中的datatime转换为DateTime_Sql Server_Vb.net_Web Services_Ado.net_Datatable - Fatal编程技术网

Sql server 在VB.NET中使用ADO.NET将sql Server中的datatime转换为DateTime

Sql server 在VB.NET中使用ADO.NET将sql Server中的datatime转换为DateTime,sql-server,vb.net,web-services,ado.net,datatable,Sql Server,Vb.net,Web Services,Ado.net,Datatable,我在VisualStudio2005中使用VB.NET语言创建了一个Web服务。此Web服务通过ADO.NET与Sql Server上的数据库交互。 使用ADO.NET,我得到了一个包含以下代码的表 conn = New SqlConnection(Utilities.ConnectionString) sqlcmd = New SqlClient.SqlCommand() sqlcmd.Connection = conn sqlcmd.CommandType =

我在VisualStudio2005中使用VB.NET语言创建了一个Web服务。此Web服务通过ADO.NET与Sql Server上的数据库交互。 使用ADO.NET,我得到了一个包含以下代码的表

    conn = New SqlConnection(Utilities.ConnectionString)
    sqlcmd = New SqlClient.SqlCommand()
    sqlcmd.Connection = conn
    sqlcmd.CommandType = CommandType.Text
    sqlcmd.CommandText = "select * from myTable" 
    da = New SqlClient.SqlDataAdapter()
    da.SelectCommand = sqlcmd
    table = New DataTable()
    da.Fill(table)
其中,Utilities是我创建的用于管理和返回ConnectionString的类。 表myTable包含多个字符串类型的字段和一个名为LastChangeDate的datetime字段。 我希望选择myTable行中的所有日期,因此我使用以下代码:

     Dim d As DateTime 
     For Each row In table.Rows
          d = row.Item("LastChangeDate")
          '
          ' other codes for managing the retuned dates
          '
问题是,在此操作之后,d包含空值


如何将VB.NET中从Item方法返回的datetime正确转换为datetime

如果数据库中的
LastChangeDate
列允许空值,则无法将空值转换为日期。在尝试使用
行将其转换为日期之前,您需要检查空值。IsNull(“LastChangeDate”)
我知道,根据我的数据,LastChangeDate字段中不包含任何空值。那么我想您的意思是d包含
无任何内容。
来自@shahkalpesh的anser应该可以帮助您。
dim isDate as Boolean
dim lastChangeDate as Date

isDate = Date.TryParse(row.Item("LastChangeDate"), lastChangeDate)
If isDate Then
  '** code that should work with the extracted date ...
End If