[英]Why am i getting this error ? Conversion from string "Invoice" to type 'Integer' is not valid
I am trying to get data from DB using datatable and then pass it into my textbox.我正在尝试使用数据表从数据库获取数据,然后将其传递到我的文本框中。 Here are my codes.
这是我的代码。 The error occurs from my first line me.txtInvoice.text.
错误发生在我的第一行 me.txtInvoice.text。
Try
dtTable = MyBase.appMgr.fncTransactionSuccessful_Sel("1", strErrMsg)
If strErrMsg = String.Empty Then
If dtTable.Rows.Count > 0 Then
Me.txtInvoiceNo.Text = dtTable("Invoice").ToString
Me.txtAmountPaid.Text = "RM " & dtTable("Amount").ToString
Me.txtPaymentDate.Text = dtTable("PaymentDate").ToString
Me.txtPackageSelected.Text = dtTable("PackageSelected").ToString
Me.txtPackageStartDate.Text = dtTable("PackageStartDate").ToString
Me.txtPackageEndDate.Text = dtTable("PackageEndDate").ToString
End If
<div class="form-group col-lg-6 col-md-12 col-sm-6" style="margin-bottom: 0px; margin-top: 17px">
<asp:TextBox ID="txtInvoiceNo" runat="server" Text="123466" CssClass="form-control"></asp:TextBox>
</div>
Perhaps you meant to do this:也许你打算这样做:
dtTable = MyBase.appMgr.fncTransactionSuccessful_Sel("1", strErrMsg)
If strErrMsg = String.Empty Then
If dtTable.Rows.Count > 0 Then
Dim ro = dtTable(0) 'get the first row out of the table
Me.txtInvoiceNo.Text = ro("Invoice").ToString
Me.txtAmountPaid.Text = "RM " & ro("Amount").ToString
Me.txtPaymentDate.Text = ro("PaymentDate").ToString
Me.txtPackageSelected.Text = ro("PackageSelected").ToString
Me.txtPackageStartDate.Text = ro("PackageStartDate").ToString
Me.txtPackageEndDate.Text = ro("PackageEndDate").ToString
End If
If you use strongly typed datasets it will make your life easier.如果您使用强类型数据集,它将使您的生活更轻松。 With a strongly typed table this code could look like:
对于强类型表,此代码可能如下所示:
dtTable = MyBase.appMgr.fncTransactionSuccessful_Sel("1", strErrMsg)
If strErrMsg <> String.Empty Then
'do something here
Return
End If
If dtTable.Count > 0 Then
Dim ro = dtTable(0) 'get the first row out of the table
Me.txtInvoiceNo.Text = ro.Invoice
Me.txtAmountPaid.Text = "RM " & ro.Amount
Me.txtPaymentDate.Text = ro.PaymentDate
Me.txtPackageSelected.Text = ro.PackageSelected
Me.txtPackageStartDate.Text = ro.PackageStartDate
Me.txtPackageEndDate.Text = ro.PackageEndDate
End If
Meaning Intellisense helps you with the columns because they are proper Properties with a correct datatype含义 Intellisense 可以帮助您处理列,因为它们是具有正确数据类型的正确属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.