将gridview绑定到OracleDataReader中的数据

时间:2012-05-08 09:21:01

标签: .net visual-studio-2010 gridview oracle10g

任何人都可以建议我如何改变这个? 当GetAlerts将数据返回到gridview时,似乎在“NOP_TEXT”中为每个字符添加一行,例如,如果NOP_TEXT包含“引用客户”,我将在gridview中获得17行...

感谢

 protected void Button2_Click(object sender, EventArgs e)
    {
            GridView1.DataSource = dal.GetAlerts(TextBox2.Text);

    }

public string GetAlerts(string partyRef)
    {
        string al_sql = "SELECT NOTEPADS_PEOPLE.NOP_TEXT "
            + "FROM FSC.PARTIES  PARTIES_PEOPLE, NOTE_TYPES  NOTE_TYPES_PEOPLE, NOTEPADS  NOTEPADS_PEOPLE "
            + "WHERE ( PARTIES_PEOPLE.PAR_REUSABLE_REFNO=NOTEPADS_PEOPLE.NOP_REUSABLE_REFNO(+)  ) "
            + "AND  ( NOTEPADS_PEOPLE.NOP_NTT_CODE=NOTE_TYPES_PEOPLE.NTT_CODE(+)  ) "
            + "AND  ( NOTE_TYPES_PEOPLE.NTT_CODE  =  'ALERT' AND PARTIES_PEOPLE.PAR_REFNO = " + partyRef + ")" ;
        string al_set = RetrieveAlert(al_sql, ":partyRef", partyRef);
        return al_set;
    }

public string RetrieveAlert(string al_sql, string cmdKey, string cmdValue)
    {
        OracleConnection al_con = null;
        OracleDataReader al_reader = null;

        al_con = new OracleConnection(Helper.HousingDBConnectionString);
        OracleCommand cmd = new OracleCommand(al_sql, al_con);
        cmd.Parameters.Add(cmdKey, cmdValue);
        al_con.Open();
        al_reader = cmd.ExecuteReader();
        string al_recset = "No Alerts";
        if (al_reader.Read())
        {
            al_recset = "ALERT: " + al_reader["NOP_TEXT"].ToString();
            return al_recset;
        }
        return al_recset;
    }

1 个答案:

答案 0 :(得分:0)

尝试:

protected void Button2_Click(object sender, EventArgs e)
    {
            GridView1.DataSource = new string[]{dal.GetAlerts(TextBox2.Text)};
    }