如何获取数据到我的网页 [英] How to get the data onto my webpage

查看:103
本文介绍了如何获取数据到我的网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的code和我不知道将在code键使数据显示了一下。我有头,但我只需要与数据有所帮助。

I have this code and i am not sure what to put to in the code to make the data show up. I have the headers but i just need help with the data.

  public string wogrid()
    {
      string htmlStr = "";
      SqlCommand cmd = con.CreateCommand();
      cmd.CommandText = "SELECT * owner";
      con.Open();
      SqlDataReader reader = cmd.ExecuteReader();

      while (reader.Read())
      {
        int OwnerID = reader.GetInt32(0);
        string OwnerID = reader.GetString(1);
        int  = reader.GetInt32(2);
        string location = reader.GetString(3);               
      }

      con.Close();
      return htmlStr;
    }

    /*****source code must me like ******/

    <table width="100%" align="center" cellpadding="2" cellspacing="2" border="0"    bgcolor="#EAEAEA" >
    <tr align="center" style="background-color:#004080;color:White;" >
    <td width="20%"> OwnerID </td>                        
    <td width="20%"> fname </td>            
    <td width="20%">lname</td>  
    <td width="20%">street</td>
    <td width="20%">zip</td> 
    <td width="20%">phone</td>                       
  ![enter image description here][1]   </tr>

推荐答案

下面是我用编程方式来提取数据,并加入到一个ASPX前端。这仅仅是除了现有的code你上面提到的。

Below is what I use to pull data programmatically and add to a ASPX front-End. This is just in addition to your existing code you referenced above.

C#:

public string wogrid()
{
    string htmlStr = "";
    SqlCommand cmd = con.CreateCommand();
    cmd.CommandText = "SELECT * owner";
    con.Open();
    SqlDataReader reader = cmd.ExecuteReader();
    DataSet ds = new DataSet();

    ds.Tables.Add("Invoices");
    ds.Tables["Invoices"].Columns.Add("OwnerID");
    ds.Tables["Invoices"].Columns.Add("First Name");
    ds.Tables["Invoices"].Columns.Add("Last Name");
    ds.Tables["Invoices"].Columns.Add("Street");
    ds.Tables["Invoices"].Columns.Add("Zip");

    while (reader.Read())
    {
        //Get your data by line.
        string1 = reader.GetInt32(0);
        string2 = reader.GetInt32(1);
        string3 = reader.GetInt32(2);
        string4 = reader.GetInt32(3);
        string5 = reader.GetInt32(4);
        ds.Tables["Invoices"].Rows.Add(string1, string2, string3, string4, string5 );
    }

    GridViewStatements.DataSource = ds;
    GridViewStatements.DataBind();
}

ASPX:

<asp:GridView ID="GridViewStatements" runat="server" HeaderStyle-BackColor="Silver" SelectedRowStyle-BackColor="#99CCFF" SelectedIndex="0" Font-Size="Medium" RowStyle-Height="50px"></asp:GridView>

这篇关于如何获取数据到我的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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