Sousa Pambo

Sousa Pambo

  • NA
  • 92
  • 23.9k

CHECK A LISTVIEW WITH A SPECIFIC DATA

Mar 3 2015 3:43 PM
HI, I NEED A HELP WITH MY CODE. IT WAS WORKING PERFECTLY. IT'S TO CHECK A LISTVIEW BY THE SPECIFIC DATA FROM SQL DATABASE AND BY THE SPECIFIC STUDENT ID. BUT NOW IT'S IGNORING A ID, I DON'T KNOW IF MY QUERY IS NOT OK. YOU MAY SEE MY CODE BELOW.
 
public string DocExist(string doc)      
{
string sql = "Select DocDescr From tbAlunoDoc where DocDescr ='" + doc + "'";
using (SqlConnection myconn = new SqlConnection(con.stringConexaoRH()))
{
try
{
myconn.Open();
using (SqlCommand comand = new SqlCommand(sql, myconn))
{
SqlDataReader dtreader = comand.ExecuteReader();
{
if (dtreader.Read())
{
return dtreader["DocDescr"].ToString();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
return "-----";
}
public void CheckDocs(ListView ls, string ID)  // to check a listview if a doc exist in the first method, but it ignoring a ID it takes all the docs doesn't exist                                                                                                                   ........//at the another table
 
{
string docmt = "";
string sql = "Select distinct id, descricao, idAlunoDoc from tbDocs, tbAlunoDoc where idAlunoDoc ='" + ID + "'";
ls.Items.Clear();
ListViewItem lst = new ListViewItem();
using (SqlConnection myconn = new SqlConnection(con.stringConexaoRH()))
{
try
{
myconn.Open();
using (SqlCommand comand = new SqlCommand(sql, myconn))
{
SqlDataReader dtreader = comand.ExecuteReader();
{
while (dtreader.Read())
{
lst = ls.Items.Add(dtreader["id"].ToString());
docmt = DocExist((dtreader["descricao"]).ToString());
if (docmt == "")
{
//got = 1;
lst.ForeColor = Color.Black;
}
else
{
//got = 2;
lst.ForeColor = Color.OrangeRed;
lst.Checked = true;
}
lst.SubItems.Add(dtreader["descricao"].ToString());
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
 
_________________
form
 
AlDal.CheckDocs(this.lstVwDocs, this.tbRefCadastro.Text);
 
I hope you get the point and help me because i'm done. 
 

Answers (3)