Click here to Skip to main content
15,565,474 members
Home / Discussions / C#
   

C#

 
GeneralRe: Getting Square Root of BigInteger Pin
harold aptroot24-Oct-12 7:52
harold aptroot24-Oct-12 7:52 
GeneralRe: Getting Square Root of BigInteger Pin
Matt T Heffron24-Oct-12 8:11
professionalMatt T Heffron24-Oct-12 8:11 
GeneralRe: Getting Square Root of BigInteger Pin
n.podbielski24-Oct-12 8:16
n.podbielski24-Oct-12 8:16 
GeneralRe: Getting Square Root of BigInteger Pin
harold aptroot24-Oct-12 9:58
harold aptroot24-Oct-12 9:58 
GeneralRe: Getting Square Root of BigInteger Pin
n.podbielski24-Oct-12 11:09
n.podbielski24-Oct-12 11:09 
QuestionWebService - WSDL choice element Pin
marosprog22-Oct-12 21:27
marosprog22-Oct-12 21:27 
QuestionMigrating Screwturn Wiki content to Sharepoint wiki Pin
chuckdawit22-Oct-12 10:21
chuckdawit22-Oct-12 10:21 
QuestionNeed assistance with Excel and datagrid Pin
yoni.kess22-Oct-12 2:35
yoni.kess22-Oct-12 2:35 
Hi All,
i need assistance with reading an excel file, writing it to a datagrid (this i already have in my code) and then for each line in the datagrid i need the following.
if a cell value is xxx in column y then do....
for example:
i have a column called "vehicle/pedestrian" now i want the following:
for each line in the datagrid if cell value in this column (vehicle......) then do.......

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
using System.Runtime.InteropServices;

namespace Datagridtest
{
    public partial class Form1 : Form
    {
        private void BrowseBtn_Click(object sender, EventArgs e)
        {
            FilePathBrowse.Filter = "SIT Files (*.xls) | *.Xls";
            if (FilePathBrowse.ShowDialog() == DialogResult.OK)
            {
                if (FilePathBrowse.FileName != "")
                    //  FileNamePath.Text = FilePathBrowse.FileName;
                    FilePath.Text = FilePathBrowse.FileName;
            }
        }
     //   const string fileName = @"c:\testing.xls";

        private DataTable dt;

        public static string BuildExcelConnectionString(string Filename, bool FirstRowContainsHeaders)
        {
            return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';Extended Properties=\"Excel 8.0;HDR={1};\"",
                                Filename.Replace("'", "''"),
                                FirstRowContainsHeaders ? "Yes" : "No");
        }
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            string fileName = FilePath.Text;
            if (!File.Exists(fileName))
            // if (!File.Exists(FilePathBrowse.FileName))
            {
                MessageBox.Show("Cannot find file");
                return;
            }

            string connStr = BuildExcelConnectionString(fileName, true);
            using (OleDbConnection conn = new OleDbConnection(connStr))
            {
                conn.Open();
                using (OleDbCommand cmd = new OleDbCommand("Select * From [Sheet1$]", conn))
                {
                    using (OleDbDataReader dr = cmd.ExecuteReader())
                    {
                        if (dt != null)
                            dt.Dispose();
                        dt = new DataTable();
                        dt.Load(dr);
                    }
                }
            }

            //  dt.Columns.Add(new DataColumn("FilterColumn", typeof(int)));
            //foreach (DataRow row in dt.Rows)
            //{
            //    //   MessageBox.Show("bla");
            //    //  int filterCode = default(int);

            //    //  if (row["Code"] == DBNull.Value)
            //    //    filterCode = -1;
            //    //  else
            //    //  {
            //    //    int code = Convert.ToInt32(row["Code"]);
            //    //    if ((code >= 90) && (code < 100))
            //    //      filterCode = 1;
            //    //    else if ((code >= 100) && (code < 110))
            //    //      filterCode = 2;
            //    //  }

            //    //  row["FilterColumn"] = filterCode;
            //    //}

            //}
            dataGridView1.DataSource = dt;




        }

                       
        }
    }


the excel i have is something like this

point	Long	Lat	FOV	[pedestrian / vehicle]	[single / multiple]	Target Location	LOS/Detection	Freetext
1	-73.882644	40.692344	5	Vehicle	Multi TGT	Road	MIN DET Range	Your Fee text here
2	-73.882903	40.69259	2	Pedestrian	Single TGT	sidewalk	DET from PREV to this PT	Your Fee text here


thanks alot.
Jonathan
AnswerRe: Need assistance with Excel and datagrid Pin
Richard MacCutchan22-Oct-12 4:27
mveRichard MacCutchan22-Oct-12 4:27 
GeneralRe: Need assistance with Excel and datagrid Pin
yoni.kess22-Oct-12 7:47
yoni.kess22-Oct-12 7:47 
GeneralRe: Need assistance with Excel and datagrid Pin
Richard MacCutchan22-Oct-12 8:31
mveRichard MacCutchan22-Oct-12 8:31 
GeneralRe: Need assistance with Excel and datagrid Pin
yoni.kess23-Oct-12 1:02
yoni.kess23-Oct-12 1:02 
GeneralRe: Need assistance with Excel and datagrid Pin
Richard MacCutchan23-Oct-12 1:18
mveRichard MacCutchan23-Oct-12 1:18 
QuestionlistBox Item Removal Pin
electriac22-Oct-12 1:42
electriac22-Oct-12 1:42 
AnswerRe: listBox Item Removal Pin
electriac22-Oct-12 2:07
electriac22-Oct-12 2:07 
GeneralRe: listBox Item Removal Pin
V.22-Oct-12 2:27
professionalV.22-Oct-12 2:27 
AnswerRe: listBox Item Removal Pin
BobJanova22-Oct-12 5:22
BobJanova22-Oct-12 5:22 
GeneralRe: listBox Item Removal Pin
electriac22-Oct-12 6:48
electriac22-Oct-12 6:48 
GeneralRe: listBox Item Removal Pin
DaveyM6922-Oct-12 12:41
professionalDaveyM6922-Oct-12 12:41 
GeneralRe: listBox Item Removal Pin
electriac23-Oct-12 11:22
electriac23-Oct-12 11:22 
GeneralRe: listBox Item Removal Pin
DaveyM6923-Oct-12 23:36
professionalDaveyM6923-Oct-12 23:36 
GeneralRe: listBox Item Removal Pin
BobJanova24-Oct-12 7:27
BobJanova24-Oct-12 7:27 
GeneralRe: listBox Item Removal Pin
DaveyM6924-Oct-12 22:30
professionalDaveyM6924-Oct-12 22:30 
GeneralRe: listBox Item Removal Pin
electriac24-Oct-12 13:35
electriac24-Oct-12 13:35 
AnswerRe: listBox Item Removal Pin
Braj_1223-Oct-12 3:36
Braj_1223-Oct-12 3:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.