C# .NET - remove extra text - Asked By Priyanka on 13-Feb-12 02:08 AM

listView2.Items.Clear();

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\db1.mdb;Persist Security Info=True;Jet OLEDB:Database Password=1234567788");

con.Open();


string sql = "select roomno,flag from roominformation where floor = 'first';";

OleDbCommand com = new OleDbCommand(sql, con);

OleDbDataReader dr = com.ExecuteReader();

while (dr.Read())

{


ListViewItem b = new ListViewItem();

b.Text = dr.GetString(0);

listView2.Items.Add(b.ToString(), 0);

}

i am using above code to show items in the list view and also image on index zero from image list.. this code is working fine but it adds some extra letters to result.. for ex.. it should result like 1002.. but it is showing like ListViewItem : {1002} this. it is working correctly when i use code like this  listView2.Items.Add(b); but when i adds .ToString() to this then the problem starts becoz without using .ToString() it doesnt accept image index.... show me the correct way so that i remove extra text from the result..

Web Star replied to Priyanka on 13-Feb-12 03:05 AM
if you are fetching roomno from database and than adding it to listview2 than you you are using additional line to create ListViewItem you should directly add item as follows

while (dr.Read())

{

 //remove two additional line from here and put direct value in add mehtod of list item

listView2.Items.Add(dr.GetString(0) , 0);

}

Priyanka replied to Web Star on 13-Feb-12 03:27 AM
thanks brother....
Priyanka replied to Web Star on 13-Feb-12 03:27 AM
thanks brother....
Web Star replied to Priyanka on 13-Feb-12 04:06 AM
You welcome! borther......