id been working on this for days now, maybe someone could help me figure this one, i have this items in listbox2, my database has a field for project, data directory, etc... if my first item in listbox2 equals to the field PROJECT in my database, i want to get the data directory of that item which is in the field of data directory, but im having problem with my if statement,(comparing the value of listbox2.items[0] to MyDataTable) please help me... thank you in advance...
private void btnConnect_Click(object sender, EventArgs e)
{
bool MyCon1_suc = false;
{
if (MyCon1 != null && MyCon1.State == ConnectionState.Open)
{
MyCon1.Close();
MyCmd1.Dispose();
}
try
{
//connecting to database
MyCon1 = new OleDbConnection();
MyCon1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\" + txtPath.Text;
MyCon1.Open();
MyCmd1 = MyCon1.CreateCommand();
MessageBox.Show("Connected to " + txtPath.Text, "Dbase connection!!!");
MyCon1_suc = true;
string commandString = "Select * from Replicate";
MyDataAdapter1 = new OleDbDataAdapter(commandString, MyCon1);
DataSet ds = new DataSet();
MyDataAdapter1.Fill(ds, "Replicate");
MyDataTable = ds.Tables["Replicate"];
listBox1.DataSource = ds.Tables["Replicate"];
listBox1.DisplayMember = "Project";
listBox1.ValueMember = "Project";
if (MyDataTable.Columns["Project"].ToString () != null)
{
int i = 0;
do
{
if (listBox2.Items[0].ToString() == MyDataTable.Rows[i]["Projects"].ToString())
// im having problem here, comparing my listbox2.item to mydatatables, it jumps to catch{} after reading my if
{
string DIR = MyDataTable.Rows[i]["Data_Directory"].ToString();
MessageBox.Show("C:\\ " + DIR);
}
i++;
} while (ds.Tables["Replicate"] != null);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
//EnableCommand(MyCon1_suc);
}
}