Hi,
I am an newbie in C#. I am entering data in an ListView control after retrieving data from the SQL Sever database using OleDbConnection, OleDbCommand and OleDbDataReader classes. The code is given below. Pls let me know where I am going wrong?? I am using VS2005 and the code does not throws any exceptions, also the data is getting retrieved correctly, but only not being populated in the ListView control.
public void DisplayRecords(OleDbDataReader rows, string str)
{
listViewDetails.Clear();
try
{
if (str.CompareTo("DETAILS") == 0)
{
int nCount = rows.FieldCount; //nCount returns 7 (fields)
ListViewItem lvi = new ListViewItem();
for (int i = 0; i < nCount; i++)
{ //Adding colums headers
ColumnHeader header = new ColumnHeader();
header.Width = 100;
header.Text = rows.GetName(i);
listViewDetails.Columns.Add(header.Text);
}
//Data population
while (rows.Read() == true)
{
lvi = listViewDetails.Items.Add(rows.GetValue(0).ToString());
for (int i = 1; i < nCount; i++)
{
lvi.SubItems.Add(rows.GetValue(i).ToString());
}
}
}
}
Loading
Bechir BejaouiPosted Dec 21, 2008, 5:26 PM
ListView1.DataSource = sqlcommand.ExecuteReader(CommandBehavior.CloseConnection);
ListView1.DataBind();
XMarshall XMarshallPosted Dec 21, 2008, 9:57 AM
//
// listViewDetails
//
this.listViewDetails.FullRowSelect = true;
this.listViewDetails.GridLines = true;
this.listViewDetails.Location = new System.Drawing.Point(16, 77);
this.listViewDetails.MultiSelect = false;
this.listViewDetails.Name = "listViewDetails";
this.listViewDetails.Size = new System.Drawing.Size(487, 261);
this.listViewDetails.TabIndex = 10;
this.listViewDetails.UseCompatibleStateImageBehavior = false;
this.listViewDetails.View = System.Windows.Forms.View.Details;
Bechir BejaouiPosted Dec 21, 2008, 7:40 AM
try this instead, are you sure that str is set to details when you are calling the method
if (str == "DETAILS")