question

CheeFaiy-9148 avatar image
0 Votes"
CheeFaiy-9148 asked LanHuang-MSFT commented

How to insert datatable into database using vb.net and asp.net ?

I have this code for grid view

    <asp:GridView ID="grdNewClaim" CssClass="table table-bordered table-condensed" 
             GridLines="None" runat="server" AutoGenerateColumns="false"
             ShowHeaderWhenEmpty="true" >
     <Columns>
         <asp:BoundField DataField="claim_type" HeaderText="Claim Type" />
         <asp:BoundField DataField="purpose_desc" HeaderText="Purpos/Description" />
         <asp:BoundField DataField="currency" HeaderText="Currency" />
         <asp:BoundField DataField="amount" HeaderText="Amount" />
         <asp:TemplateField HeaderText="Currency Rate">
            <ItemTemplate>
                 <asp:TextBox ID="txtCRateZoo" runat="server"
                     Text = '<%# Eval("txtChangeCurrRate") %>'>
                 </asp:TextBox>
            </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Converted Rate">
             <ItemTemplate>
                 <asp:TextBox ID="txtConvertedRate" runat="server"                        
                     Text = '<%# Eval("txtChangeCurrRate") %>' >
    
                 </asp:TextBox>
             </ItemTemplate>
         </asp:TemplateField>
     </Columns>
 </asp:GridView>

Everything works just fine until I want to insert the datatable into database. The value in the textboxes rows becomes 0.00000 instead of the actual values for example 23.56. The other values inserted correctly and just fine. This is the code to insert into database.

    Private Function AddClaim() As Integer
         If grdNewClaim.Rows.Count > 0 Then
             For i = 0 To grdNewClaim.Rows.Count - 1
                 Using insertDetail As New clshrReimbursementclaimdetaildal
                     Dim obj As New clshrReimbursementclaimdetailsinfo
                     With obj
                         .parent_id = clsCommon.ToInt(lblHiddenID.Text)
                         .claim_type = grdNewClaim.Rows(i).Cells(1).Text
                         .purpose_desc = grdNewClaim.Rows(i).Cells(2).Text
                         .currency = grdNewClaim.Rows(i).Cells(3).Text
                         .amount = clsCommon.ToDbl(grdNewClaim.Rows(i).Cells(4).Text)
                         .currency_rate = clsCommon.ToDbl(grdNewClaim.Rows(i).Cells(5).Text)
                         .converted_rate = clsCommon.ToDbl(grdNewClaim.Rows(i).Cells(6).Text)
                         .created_by = Membership.GetUser.ProviderUserKey
                     End With
                     Dim intResult As Integer = insertDetail.insertDetail(obj)
                 End Using
             Next
         End If
         Return 1
     End Function
dotnet-visual-basicdotnet-aspnet-webpages
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @CheeFaiy-9148,
You only provided part of the code and it's hard to reproduce your problem.

The value in the textboxes rows becomes 0.00000 instead of the actual values for example 23.56. The other values inserted correctly and just fine.

<asp:TextBox ID="txtConvertedRate" runat="server" Text = '< % # E v a l("txtChangeCurrRate") %>' >
How did you get the txtChangeCurrRate value?
Maybe you can provide more detailed code so we can help you.
Best regards,
Lan Huang
1 Vote 1 ·

More details on the following would assist those here to help to understand these two lines.

225747-figure1.png


0 Votes 0 ·
figure1.png (49.4 KiB)

0 Answers