ListView listView1 = new ListView();
        DataTable dataTable = new DataTable();
        MoneyReceiptGateway moneyReceiptGateway = new MoneyReceiptGateway();
        dataTable = moneyReceiptGateway.SelectDataForListView(narrationTextBox.Text);
        string[] str = new string[dataTable.Columns.Count];
        foreach (DataRow rr in dataTable.Rows)
        {
            for (int coll = 0; coll <= dataTable.Columns.Count; coll++)
            {
                str[coll] = rr[coll].ToString();
            }
            ListViewDataItem li;
            li = new ListViewDataItem(str);
            listView1.Items.Add(li);
        }
 public DataTable SelectDataForListView(string txtSubHead)
    {
        int length = txtSubHead.Length;
        string aa = txtSubHead.Substring(0, length);
        connection = ConfigurationManager.AppSettings["ConnectionString"];
        sqlConnectionObj = new SqlConnection(this.connection);
        string insertQuery = @"select S.SubName,M.MainName, A.ClassName from AcClass as A, MainClass as M, SubClass as S WHERE (S.AcCode=A.AcCode) and (S.AcCode=M.AcCode) 
                           and (S.MainCode=M.MainCode) and  (substring(S.subname,1,'" + length + "')='" + txtSubHead + "') or (substring(M.MainName,1,'" + length + "')='" + txtSubHead + "' )  ORDER BY S.SubName";
        
        sqlConnectionObj.Open();
        adapter = new SqlDataAdapter(insertQuery, sqlConnectionObj);
        dataTable=new DataTable();
        adapter.Fill(dataTable);
        return dataTable;
    }

error message is:Error 3 The best overloaded method match for 'System.Windows.Forms.ListView.ListViewItemCollection.Add(string)' has some invalid argument

It seems to be because you are dimensioning "li" as a ListViewDataItem but then are trying to pass it as a string. Perhaps you should dim it as a string OR leave as is but see if this type has a "ToString()" method when you add it.
(i.e. "...Collection.Add(li.ToString())

Are you using the System.Windows.Forms.ListView or the System.Web.UI.WebControls.ListView? From the error (and usage) you are trying to use the Forms one, but then trying to force a web data item into the control. Which did you intend to use?

i a m using System.Web.UI.WebControls.ListView
but problem is still on first line
li = new ListViewItem(str);
listView1.Items.Add(li.ToString());
so what to do now?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.