我试图读取最后一张发票号并将其显示在文本框中.....
假设,表名是" MyTable" ,列名是" InvoiceNumber"它是自动编号,所以它是整数!
这是我的代码:
Dim query As String = "SELECT MAX(InvoiceNumber) FROM MyTable"
Dim cmd As New OleDb.OleDbCommand
Dim reading As OleDb.OleDbDataReader
cmd.CommandText = query
cmd.Connection = conn
reading = Convert.ToInt32(cmd.ExecuteScalar())
If reading.Read Then
TextBox1.Text = reading.Item("InvoiceNumber").ToString
End If
Erorr on" reading = Convert.ToInt32(cmd.ExecuteScalar())"因为我的价值是'整数'无法转换为System.Data.OleDb.OleDbDataReader'。
任何帮助......?
答案 0 :(得分:1)
变量reading
是OleDbDataReader
,它不能用于分配整数,这就是错误的原因。但是,如果您使用DataReader
:
ExecuteScalar
Dim maxNumber As Int32 = Convert.ToInt32(cmd.ExecuteScalar())
TextBox1.Text = maxNumber.ToString