【发布时间】:2020-02-11 15:04:45
【问题描述】:
我有这个错误,
无法将“System.Int32”类型的对象转换为“System.String”类型。
代码可以运行,但是重建后代码不再运行
我的代码
Private Sub KodePembelian()
Dim Rd As SqlClient.SqlDataReader
Dim Cmd As SqlClient.SqlCommand
Dim bulan As String
bulan = Format(Now, "MM")
Dim tahun As String
tahun = Format(Now, "yy")
Dim Urutan As String
Dim Hitung, Cari As String
Cmd = New SqlClient.SqlCommand("SELECT * FROM BY_PEMBELIANHEADER WHERE NOPEMBELIAN IN " & "(SELECT MAX (NOPEMBELIAN) FROM BY_PEMBELIANHEADER)", MyConn)
Rd = Cmd.ExecuteReader
Rd.Read()
If Not Rd.HasRows Then
Urutan = "PO/" & bulan & tahun & "/" & "000001"
Else
Cari = Microsoft.VisualBasic.Right(Rd.GetString(0), 6)
If Microsoft.VisualBasic.Left(Rd.GetString(0), 8) <> "PO/" & bulan & tahun & "/" Then
Urutan = "PO/" & bulan & tahun & "/" & "000001"
Else
Hitung = Microsoft.VisualBasic.Right(Rd.GetString(0), 6) + 1
Urutan = "PO/" & bulan & tahun & "/" & Microsoft.VisualBasic.Right("000000" & Hitung, 6)
End If
End If
Rd.Close()
txtpo.SelectedText = Urutan
End Sub
【问题讨论】:
-
你不应该在调用 read 之前检查阅读器是否有行吗?
-
如果您使用
SELECT *,则可以按任何顺序返回列。如果列顺序很重要,请列出列名而不是使用*。
标签: vb.net