如何从XML数据和sql表数据填充网格视图 [英] how to Fill grid view from both XML data and sql table data

查看:84
本文介绍了如何从XML数据和sql表数据填充网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多字段的网格视图,这里我正在从XML文件中检索数据,并且还希望从表中再获取一列.我怎么能从桌子上拿走呢?

这是我尝试从XML文件检索数据的以下代码.
代码隐藏

I have a grid view that contain many fields, here I am retrieving data from XML file and want to take one more column from the table also. how can i take that from the table.

This is the below code I have tried to retrieve data from XML file.
CODE BEHIND

protected void btnviewdata_Click(object sender, EventArgs e)
{
    GridView1.Visible = true;
    SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=TNVKP_8;Integrated Security=True");
    con.Open();
    DataSet reportData = new DataSet();
    reportData.ReadXml(Server.MapPath("XMLFILENAME.xml"));
    GridView2.DataSource = reportData;
    GridView2.DataBind();
    con.Close();
}


ASPX代码


ASPX code

<asp:GridView ID="GridView1" runat="server" Width="96%" PageSize="10" AutoGenerateColumns="False">
                    <Columns>                               
            <asp:TemplateField HeaderText="Select">
                <ItemTemplate>
                    <asp:CheckBox ID="chkbox" runat="server"></asp:CheckBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="TALLY_REC_ID_CODE" HeaderText="Tally_No" />
            <asp:BoundField DataField="CLUSTER_ID" HeaderText="Cluster_ID"/>
            <asp:BoundField DataField="UNIT_TYPE" HeaderText="Unit_Type" />
            <asp:BoundField DataField="VPRC_ID" HeaderText="VPRC_ID" />
            <asp:BoundField DataField="SHG_ID" HeaderText="SHG_ID" />
            <asp:BoundField DataField="PIP_NO" HeaderText="Pip_No" />
            <asp:BoundField DataField="NAME_OF_THE_MEMBER" HeaderText="Member_Name" />
            <asp:BoundField DataField="TYPE_OF_LOAN" HeaderText="Type_of_Loan" />                  
            <asp:BoundField DataField="PRINCIPAL" HeaderText="Principal" />
            <asp:BoundField DataField="INTEREST" HeaderText="Interest" />
            <asp:TemplateField HeaderText="PipNo.">
                <ItemTemplate>
                    <asp:Label ID="PIPCODE" runat="server"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Remark">
                <ItemTemplate>
                    <asp:Label ID="lblremark"  runat="server"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            </Columns>
                    </asp:GridView>  


在此PIPCODE标签中,我要从sql服务器获取数据.

如果XML pipno等于我的表pipno,那么我想检索pipno的等效代码.

以及如何编写查询以从表中选择pipcode的查询,因为我想从XML中获取pipno并与SQL匹配,然后我要从表中选择等效的pipcode并应在最后一列中查看网格视图.
如果pipcode可用,则注释等于OK,如果pipno不可用,则注释等于NOT IN DB这样.

为此发布解决方案.

预先感谢.


Here in this PIPCODE label I want take data from the sql server.

If XML pipno equal my table pipno then I want to retrieve the equivalent code for the pipno.

And how can I write the query to select the pipcode from the table because I want to take the pipno from XML and match with SQL then I want to select the equivalent pipcode from table and should view in the last column of grid view.
If pipcode is available then remark equal to OK, if pipno not available then remark equal to NOT IN DB like that.

Post solution for this.

Thanks in advance.

推荐答案

1-读取XML数据并存储在数据表中.
2-从数据库中读取并存储不同的数据表并同时对两个表进行合并
3-使用ur网格视图进行绑定.
1-read XML data and store in data-table.
2-read from database and store different data-table and marge both the table
3- bind with ur grid view.



1.读取XML数据并存储在表中
2.读取SQL数据并存储在另一个表中
3.使用LINQ过滤数据.
4.将这两个表合并到一个自定义表中,您需要将该表与带有附加列的gridview绑定.

希望对您有帮助.
Hi
1. Read XML data and store in a table
2. Read SQL Data and store in a another table
3. Filter data using LINQ.
4. Merge both table in a custom table which u required to bind with gridview with additional column.

Hope this will help u.


这篇关于如何从XML数据和sql表数据填充网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆