Dim SQLcd As New SqlCommand Dim SQLdr As SqlDataReader Dim ParamStartDate As SqlParameter Dim ParamEndDate As SqlParameter Dim ParamVendorName As SqlParameter Dim StartDate As String Dim EndDate As String Dim StockStamp As Object 'TimeStamp列を格納
Do While SQLdr.Read() itemx = Me.lstStockMain.Items.Add(SQLdr!STOCK_CODE) itemx.SubItems.Add(Format(SQLdr!STOCK_DATE, "yyyy/MM/dd")) itemx.SubItems.Add(SQLdr!VENDOR_CODE) If SQLdr("VENDOR_NAME") Is DBNull.Value Then itemx.SubItems.Add("未設定") Else itemx.SubItems.Add(SQLdr!VENDOR_NAME) End If itemx.SubItems.Add(Format(SQLdr!IN_DATE, "yyyy/MM/dd HH:mm:ss.fff")) itemx.SubItems.Add(SQLdr!USER_CODE) itemx.SubItems.Add(SQLdr!PC_NAME) StockStamp = SQLdr!STOCK_STAMP itemx.SubItems.Add(StockStamp.ToString()) Loop
Dim sqlConn As SqlClient.SqlConnection = _ New SqlClient.SqlConnection("Data Source=(local);Initial Catalog=Test;Integrated Security=SSPI;") Try sqlConn.Open() Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand Try With cmd .Connection = sqlConn .CommandType = CommandType.StoredProcedure .CommandText = "TestProc" ' タイムスタンプの結果を返すストアドプロシージャ End With Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader() While (dr.Read) Me.ListView1.Items.Add(TimestampToString(DirectCast(dr("タイムスタンプ"), Byte()))) End While Finally If Not cmd Is Nothing Then cmd.Dispose() If Not sqlConn Is Nothing Then sqlConn.Close() End If End Try Finally If Not sqlConn Is Nothing Then sqlConn.Dispose() End If End Try
End Sub
Private Function TimestampToString(ByVal value As Byte()) As String Dim Buffer As String = "0x"
For i As Integer = 0 To value.Length - 1 Buffer &= Microsoft.VisualBasic.Right("00" & Hex(value(i)), 2) Next Return Buffer End Function
分類:[.NET]
いつもお世話になってます。
下記のストアドでTimeStamp列の値をListviewに表示したいのですが
なかなか上手くできません。
TimeStampの値がSystem.Byte[]となってしまいます。
CbyteやToStringも試してみたのですが、だめでした。
Sqlserverのデータをそのままに"0X000000167257"と表示したいのですが
どなたかご教授お願いいたします。
Dim SQLcd As New SqlCommand
Dim SQLdr As SqlDataReader
Dim ParamStartDate As SqlParameter
Dim ParamEndDate As SqlParameter
Dim ParamVendorName As SqlParameter
Dim StartDate As String
Dim EndDate As String
Dim StockStamp As Object 'TimeStamp列を格納
Try
StartDate = Format(Me.txtStartYear.Text & "/" & Me.txtStartMonth.Text & "/" & Me.txtStartDay.Text & Space(1) & "00:00:00.000")
EndDate = Format(Me.txtEndYear.Text & "/" & Me.txtEndMonth.Text & "/" & Me.txtEndDay.Text & Space(1) & "23:59:59.999")
Me.lstStockMain.Items.Clear()
Me.lstStockMain.Columns.Clear()
Me.lstStockMain.Columns.Add("コード", 0, HorizontalAlignment.Left)
Me.lstStockMain.Columns.Add("仕入日", 90, HorizontalAlignment.Left)
Me.lstStockMain.Columns.Add("コード", 0, HorizontalAlignment.Left)
Me.lstStockMain.Columns.Add("仕入先", 170, HorizontalAlignment.Left)
Me.lstStockMain.Columns.Add("登録日", 0, HorizontalAlignment.Left)
Me.lstStockMain.Columns.Add("コード", 0, HorizontalAlignment.Left)
Me.lstStockMain.Columns.Add("PC", 0, HorizontalAlignment.Left)
Me.lstStockMain.Columns.Add("STAMP", 50, HorizontalAlignment.Left)
SQLcd.CommandText = "SE_STOCK_MAIN_MANAGE"
SQLcd.Connection = ClassAccessSQL.SQLcn
SQLcd.CommandType = CommandType.StoredProcedure
'START_DATE
ParamStartDate = SQLcd.Parameters.Add("@START_DATE", SqlDbType.DateTime)
ParamStartDate.Value = StartDate
'END_DATE
ParamEndDate = SQLcd.Parameters.Add("@END_DATE", SqlDbType.DateTime)
ParamEndDate.Value = EndDate
'VENDOR_NAME
ParamVendorName = SQLcd.Parameters.Add("@VENDOR_NAME", SqlDbType.VarChar, 50)
ParamVendorName.Value = Me.txtVendorName.Text
'接続を開きます
ClassAccessSQL.OpenCnSSPI("KOUMEI", "PAY_MANAGE2007", False)
'ClassAccessSQL.OpenCnSSPI(ServerName, DataBase, False)
SQLdr = SQLcd.ExecuteReader
Do While SQLdr.Read()
itemx = Me.lstStockMain.Items.Add(SQLdr!STOCK_CODE)
itemx.SubItems.Add(Format(SQLdr!STOCK_DATE, "yyyy/MM/dd"))
itemx.SubItems.Add(SQLdr!VENDOR_CODE)
If SQLdr("VENDOR_NAME") Is DBNull.Value Then
itemx.SubItems.Add("未設定")
Else
itemx.SubItems.Add(SQLdr!VENDOR_NAME)
End If
itemx.SubItems.Add(Format(SQLdr!IN_DATE, "yyyy/MM/dd HH:mm:ss.fff"))
itemx.SubItems.Add(SQLdr!USER_CODE)
itemx.SubItems.Add(SQLdr!PC_NAME)
StockStamp = SQLdr!STOCK_STAMP
itemx.SubItems.Add(StockStamp.ToString())
Loop
Catch ex As SqlException
MsgBox(ex.ToString, 4112, "ERR")
Catch ex As Exception
MsgBox(ex.ToString, 4112, "ERR")
Finally
If ClassAccessSQL.SQLcn.State = 1 Then
SQLdr.Close()
ClassAccessSQL.CloseSQL(False)
End If
'Call ListCount()
Me.txtStartYear.Focus()
End Try
End Sub