Click here to Skip to main content
15,894,252 members
Home / Discussions / C#
   

C#

 
AnswerRe: VSTO 2010 Word Addin, passing arguments problem Pin
Richard Deeming24-Oct-12 2:15
mveRichard Deeming24-Oct-12 2:15 
AnswerRe: VSTO 2010 Word Addin, passing arguments problem Pin
Pete O'Hanlon24-Oct-12 3:56
mvePete O'Hanlon24-Oct-12 3:56 
QuestionWebRequest and WebResponse has issues Pin
Xarzu23-Oct-12 21:28
Xarzu23-Oct-12 21:28 
AnswerRe: WebRequest and WebResponse has issues Pin
J4amieC23-Oct-12 21:36
J4amieC23-Oct-12 21:36 
GeneralRe: WebRequest and WebResponse has issues Pin
Xarzu25-Oct-12 11:04
Xarzu25-Oct-12 11:04 
AnswerRe: WebRequest and WebResponse has issues Pin
n.podbielski23-Oct-12 22:10
n.podbielski23-Oct-12 22:10 
GeneralRe: WebRequest and WebResponse has issues Pin
Jan Steyn24-Oct-12 3:31
Jan Steyn24-Oct-12 3:31 
GeneralRe: WebRequest and WebResponse has issues Pin
Xarzu25-Oct-12 11:10
Xarzu25-Oct-12 11:10 
GeneralRe: WebRequest and WebResponse has issues Pin
n.podbielski25-Oct-12 20:14
n.podbielski25-Oct-12 20:14 
GeneralRe: WebRequest and WebResponse has issues Pin
Xarzu27-Oct-12 18:59
Xarzu27-Oct-12 18:59 
GeneralRe: WebRequest and WebResponse has issues Pin
n.podbielski27-Oct-12 20:18
n.podbielski27-Oct-12 20:18 
QuestionGetting Square Root of BigInteger Pin
gibsray23-Oct-12 7:52
gibsray23-Oct-12 7:52 
AnswerRe: Getting Square Root of BigInteger Pin
jschell23-Oct-12 8:22
jschell23-Oct-12 8:22 
SuggestionRe: Getting Square Root of BigInteger Pin
Matt T Heffron23-Oct-12 11:30
professionalMatt T Heffron23-Oct-12 11:30 
GeneralRe: Getting Square Root of BigInteger Pin
n.podbielski23-Oct-12 22:37
n.podbielski23-Oct-12 22:37 
GeneralRe: Getting Square Root of BigInteger Pin
harold aptroot24-Oct-12 4:27
harold aptroot24-Oct-12 4:27 
GeneralRe: Getting Square Root of BigInteger Pin
Matt T Heffron24-Oct-12 6:39
professionalMatt T Heffron24-Oct-12 6:39 
GeneralRe: Getting Square Root of BigInteger Pin
harold aptroot24-Oct-12 6:52
harold aptroot24-Oct-12 6:52 
GeneralRe: Getting Square Root of BigInteger Pin
Matt T Heffron24-Oct-12 7:11
professionalMatt T Heffron24-Oct-12 7:11 
GeneralRe: Getting Square Root of BigInteger Pin
n.podbielski24-Oct-12 7:16
n.podbielski24-Oct-12 7:16 
GeneralRe: Getting Square Root of BigInteger Pin
harold aptroot24-Oct-12 8:58
harold aptroot24-Oct-12 8:58 
GeneralRe: Getting Square Root of BigInteger Pin
n.podbielski24-Oct-12 10:09
n.podbielski24-Oct-12 10:09 
QuestionWebService - WSDL choice element Pin
marosprog22-Oct-12 20:27
marosprog22-Oct-12 20:27 
QuestionMigrating Screwturn Wiki content to Sharepoint wiki Pin
chuckdawit22-Oct-12 9:21
chuckdawit22-Oct-12 9:21 
QuestionNeed assistance with Excel and datagrid Pin
yoni.kess22-Oct-12 1:35
yoni.kess22-Oct-12 1: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

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.