amna naveed

amna naveed

  • NA
  • 22
  • 1.2k

hii! I want to retrive data from database into array string

Aug 15 2014 1:49 PM
I want to retrive data from database(mysql) into array string  and then want to retrive more data from database based on that array string values. plz help

here is my code

sing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Collections;

public partial class searchresult : System.Web.UI.Page
{
    public int i;
    public string comment, search,wd;
  

    protected void Page_Load(object sender, EventArgs e)
    {

    

        if (!IsPostBack)
        {
            BindParentDataList();
        

        }
    }
  

    public void BindParentDataList()
    {
       
     
        ArrayList list = new ArrayList();
      
        SqlCommand cmd1 = new SqlCommand("SELECT * from searches", con);
        cmd1.Connection = con;
        if (con.State == ConnectionState.Closed)
            con.Open();
        SqlDataReader rd = cmd1.ExecuteReader();

        rd.Read();
        list.Add(rd["strings"] + "");
         
             rd.Close();
             foreach (string s in list)
             {
                 SqlCommand cmd = new SqlCommand("select * from comment WHERE (CommentOn LIKE \'%" + (s + "%\')"), con);

            

                 SqlDataReader myDataReader = cmd.ExecuteReader();


                 parentDataList.DataSource = myDataReader;
                 parentDataList.DataBind();

                 myDataReader.Close();
             }

        if (con.State == ConnectionState.Open)
            con.Close();


i retrive data from table searches and then use the data of searches table to retrive data from comment table. help please

Answers (2)