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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.