从数据表中获取价值

时间:2013-11-08 09:32:27

标签: asp.net vb.net

有谁能告诉我如何从数据表中获取价值?我在数据表中只有一行和一列,我需要获取列的值来进行计算。

这是我的剧本

<SCRIPT Language="VB" Runat="server">

Sub Page_Load(Source as object, e as EventArgs) handles me.load

Dim connectionstring As String = "DRIVER={MySQL ODBC 5.2 Unicode Driver}; SERVER=localhost; DATABASE=mydb; UID=andrew; PASSWORD=kh12345; OPTION=3"

Dim connectme As OdbcConnection = New OdbcConnection(connectionstring)

Dim sqlquery As String = "SELECT f_name, f_price from tbl_picture WHERE f_ID = 1"

Dim ODBCdataadapter As OdbcDataAdapter = New OdbcDataAdapter(sqlquery, connectme)

Dim ODBCdataset As DataSet = New DataSet()

ODBCdataadapter.Fill(ODBCdataset)

DataTable.DataSource = ODBCdataset
DataTable1.DataSource = ODBCdataset
Datatable.DataBind()
Datatable1.DataBind()
End Sub

</SCRIPT >

<ASP:Datagrid ID="Datatable1" Runat="server" AutoGenerateColumns="False"BorderStyle="None" GridLines="None">
<Columns>
            <asp:BoundColumn 
            DataField="f_price" 
            ReadOnly="True"/>
</columns>
   </asp:DataGrid>

这是计算部分

 Private Sub CalculatePayment()
        Dim c_loan_amount, c_Payment
        Dim amount As String = Datatable1.Select("f_price")
        c_loan_amount = amount - (amount * Down.Text * 0.01)
        c_Payment = ((c_loan_amount * (Interest.Text * 0.01) * Year.Text) + c_loan_amount) / (Year.Text * 12)
        Payment.Text = "RM " & Format(c_Payment, "#,##0.00")
    End Sub

它应该是Dim金额作为字符串部分吗?我有点新鲜,提前谢谢。

1 个答案:

答案 0 :(得分:0)

您需要定义行和项目。

尝试

Dim amount As String = Datatable1.tables(0).Rows(0).Item(1)

实际上,您应该将datatable1重命名为dataset1,因为数据表是数据集的可能成员。它只是为了尽量减少对什么的混淆。

Rows告诉数据表的哪一行。该项目告诉哪个索引。

0 = f_name
1 = f_amount