mercredi 7 mars 2018

how to get excel sheet data into Checkbox using oledb connection

how to get excel sheet data into Checkbox using oledb connectionstring str1 = private void lblsearch_Click(object sender, EventArgs e) { string fileName = @"C:\Users\Spoorthi S\Desktop\mp\MohanProject\MohanProject\Data\NewProject.xls"; string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=Excel 8.0;Persist Security Info=False"; OleDbConnection con = new OleDbConnection(connectionString); con.Open(); string str = "select * from [Sheet2$] where ProjectID='" + comboBox1.Text.Trim() + "'"; OleDbCommand com = new OleDbCommand(str, con); OleDbDataReader reader = com.ExecuteReader(); if (reader.Read()) { txtEngineerName.Text = reader["CustomerEngineer"].ToString(); txtProjectName.Text = reader["Project Name"].ToString(); txtChangeDesc.Text = reader["Work Description"].ToString(); txtInputModel.Text = reader["Input Model DB Link"].ToString(); txtSowLinnk.Text = reader["SOW Link"].ToString(); txtAttachment.Text = reader["Attachments"].ToString(); dateTimePicker1.Text = reader["Delivery Date"].ToString(); } con.Close(); reader.Close(); OleDbConnection con1 = new OleDbConnection(connectionString); con1.Open(); string str1 = "select [Req Model Type] from [Sheet2$] where ProjectID='" + comboBox1.Text.Trim() + "'"; OleDbCommand com1 = new OleDbCommand(str1, con1); reqmodeltype = com1.ExecuteScalar().ToString(); checkBoxModelTypeuncheck(sender, e); con1.Close(); }

    public void checkBoxModelTypeuncheck(object sender, EventArgs e)
    {
        for (int i = 0; i < checkBoxModelType.Items.Count; i++)
        {
            if ((string)checkBoxModelType.Items[i] == reqmodeltype)
            {
                checkBoxModelType.SetItemChecked(i, true);
            }
        }
    }




Aucun commentaire:

Enregistrer un commentaire