检索数据表中的值的问题 [英] problem in retreiving values in datatable
问题描述
大家好!
我正在将两个表中的值检索到一个数据表中.数据表有两个列(月,欠款)
现在,我正在检索来自不同表的两个列的值.问题在于,它在相对于月份的正确位置显示了欠款"列的值,但没有显示月份"列的值.两个表中都有值.
这是我的代码
Hi all!!
i am retrieving values from two tables into a datatable. Datatable has two colums (Months , Arrears)
now i am retreiving values for both the columns from different tables. The problem is that it is showing value for the Arrears column at the right place with respect to month but not showing the value for month column. Both the tables has values inside them.
this is my code
Private Sub sbBindReport(ByVal eid As String, ByVal fn As String)
On Error Resume Next
Dim ds As New ds_GPFReport1()
'''' ''''
Dim frm_x As String = "01-Apr-" + fn.Substring(0, 4)
Dim frm_y As String = "31-Mar-" + fn.Substring(5, 4)
Dim x As String = "Select 0 Month , 0.0 Arrear where 1=2"
Dim da As New SqlDataAdapter(x, ConfigurationManager.ConnectionStrings("PIMSConnectionString").ConnectionString)
da.Fill(ds, "Mon")
'''' ''''Copy of main
Dim dt_copyOfMain As New DataTable()
dt_copyOfMain = Dal.GettDS(x).Tables(0)
x = "Select fn_yr ,monthID, arrear_Amt,OrderNum,OrderDt,empid "
x += " from arrears_data"
x += " where empid=" + eid + " and fn_yr=''" + fn + "''"
Dim dt_arrears As New DataTable()
dt_arrears = Dal.GettDS(x).Tables(0)
x = "Select month_num,srnum,month_e from master_month order by srnum"
Dim dt_month_order As New DataTable()
dt_month_order = Dal.GettDS(x).Tables(0)
For Each dr_month As DataRow In dt_month_order.Rows
For Each dr_arrears As DataRow In dt_arrears.Rows
If dr_month("month_num").ToString().Trim() = dr_arrears("monthID").ToString().Trim() Then
Dim dr As DataRow = dt_copyOfMain.NewRow()
dr("Arrear") = dr_arrears("arrear_Amt")
dr("Month") = dr_month("month_e").ToString()
dt_copyOfMain.Rows.Add(dr)
Else
Dim dr As DataRow = dt_copyOfMain.NewRow()
dr("Arrear") = 0.0
dr("Month") = dr_month("month_e").ToString()
dt_copyOfMain.Rows.Add(dr)
End If
Next
Next
For Each dr As DataRow In dt_copyOfMain.Rows
ds.Tables("Mon").ImportRow(dr)
Next
grd.DataSource = ds.Tables("Mon")
grd.DataBind()
End Sub
这里的eid是employeeId,而fn是财务年度.
我使用断点检查了它.它表明
here eid is employeeId and fn is the financial yr.
i checked it using break points. It''s showing that
dr_month("month_e").ToString()
在ItemArray(2)处具有值("Arpil")
但是在gridview中没有显示任何东西
我也尝试使用
has value ("Arpil") at ItemArray(2)
but it''s not showing any thing in the gridview
i also tried using
dr_month("month_e").ItemArray(2).ToString()
,但是结果是相同的.
推荐答案
请检查ds.Tables("Mon")中正在输入什么数据,否则您会理解错误
please check what data is coming in ds.Tables("Mon") than you will understand error
这篇关于检索数据表中的值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!