Click here to Skip to main content
15,909,652 members
Home / Discussions / C#
   

C#

 
GeneralRe: MD5 Conflict between PHP and C# Pin
Vasudevan Deepak Kumar8-Oct-08 13:34
Vasudevan Deepak Kumar8-Oct-08 13:34 
AnswerRe: MD5 Conflict between PHP and C# Pin
Ennis Ray Lynch, Jr.8-Oct-08 12:30
Ennis Ray Lynch, Jr.8-Oct-08 12:30 
GeneralRe: MD5 Conflict between PHP and C# Pin
Vasudevan Deepak Kumar8-Oct-08 13:35
Vasudevan Deepak Kumar8-Oct-08 13:35 
AnswerRe: MD5 Conflict between PHP and C# Pin
Mark Churchill8-Oct-08 17:06
Mark Churchill8-Oct-08 17:06 
Questionevent not fired [modified] Pin
netJP12L8-Oct-08 12:02
netJP12L8-Oct-08 12:02 
AnswerRe: event not fired Pin
DaveyM698-Oct-08 12:31
professionalDaveyM698-Oct-08 12:31 
GeneralRe: event not fired Pin
netJP12L8-Oct-08 16:58
netJP12L8-Oct-08 16:58 
QuestionError- This row already belongd to another table Pin
rahul218-Oct-08 10:40
rahul218-Oct-08 10:40 
I am reading the contents of excel file and storing contents in database.
I am using two datatables org_dt and grid_dt.
i am having a problem while adding rows to grid_dt datatable, also having problem while inserting date into this table.

here is the source code:-

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.Odbc;
using Excel;

namespace WinApp_STRINGSEPARATE
{
public partial class Frm_admin_upload_optn : Form
{
string connectionString;// @" Dsn=Excel Files;dbq=C:\Program Files\Common Files\ODBC\Data

Sources\book4.xls;defaultdir=c:\;driverid=790;maxbuffersize=2048;pagetimeout=5";

OdbcConnection conn = new OdbcConnection();
OdbcCommand cmd = new OdbcCommand();
OdbcDataReader dr;
System.Data.DataTable org_dt = new System.Data.DataTable();
System.Data.DataTable grid_dt = new System.Data.DataTable();
string project_no = "", summary = "";
string[] divpara = new string[3];

string[] yes = new string[4];

public Frm_admin_upload_optn()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

openFileDialog1.ShowDialog();
textBox1.Text = openFileDialog1.FileName;

}

private void Frm_admin_upload_optn_Load(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{
try
{
connectionString = @"Dsn=Excel Files;dbq=" + textBox1.Text.Trim()

+";driverid=790;maxbuffersize=2048;pagetimeout=5";
conn.ConnectionString = connectionString;
cmd.CommandText = "SELECT * FROM [sheet1$]";
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = conn;
conn.Open();
dr = cmd.ExecuteReader();
org_dt = new System.Data.DataTable();

if (dr.HasRows)
{
org_dt.Load(dr);
grid_dt.Columns.Add("PROJECT NO");
grid_dt.Columns["PROJECT NO"].DataType = typeof(string);
grid_dt.Columns.Add("TICKET NO");
grid_dt.Columns["TICKET NO"].DataType = typeof(string);
grid_dt.Columns.Add("REPORTED DATE");
grid_dt.Columns["REPORTED DATE"].DataType = typeof(DateTime);
grid_dt.Columns.Add("OLD COMPUTER NAME");
grid_dt.Columns["OLD COMPUTER NAME"].DataType = typeof(string);
grid_dt.Columns.Add("NEW COMPUTER NAME");
grid_dt.Columns["NEW COMPUTER NAME"].DataType = typeof(string);

DataRow grid_dt_row = grid_dt.NewRow();
for (int j = 0;j<4;j++ )
grid_dt_row[j] = "";

int count_orgdt = org_dt.Rows.Count;


int i = 0;
foreach (DataRow drow in org_dt.Rows)
{

summary = drow["summary"].ToString();
if (summary != "")
{
if (summary.Contains("Project #-"))
project_no = "Project #-";
else project_no = "Project Number #-";

divpara[0] = project_no;
divpara[1] = "New PC Name :";
divpara[2] = "Old PC Name :";
yes = summary.Split(divpara, System.StringSplitOptions.None);


//grid_dt.Rows.Add(grid_dt_row);

grid_dt.ImportRow(grid_dt_row); //ERROR MSG
grid_dt.Rows[i]["project no"] = yes[1];
grid_dt.Rows[i]["ticket no"] = drow[0];
grid_dt.Rows[i]["reported date"] =drow[3] ; // ERROR RELATED TO DATE FIELD
grid_dt.Rows[i]["old computer name"] = yes[2];
grid_dt.Rows[i]["new computer name"] = yes[3];
i++;

}


}

dataGridView1.DataSource = grid_dt;

}





}
catch (Exception e1)
{
MessageBox.Show(e1.Message);

}
finally
{
conn.Close();
}



}
}
}
AnswerRe: Error- This row already belongd to another table Pin
Richard Blythe8-Oct-08 16:14
Richard Blythe8-Oct-08 16:14 
QuestionHow do I call the combobox SelectionChangeCommitted event manually? Pin
OldSchoolToC#8-Oct-08 5:56
OldSchoolToC#8-Oct-08 5:56 
AnswerRe: How do I call the combobox SelectionChangeCommitted event manually? Pin
DaveyM698-Oct-08 6:30
professionalDaveyM698-Oct-08 6:30 
GeneralRe: How do I call the combobox SelectionChangeCommitted event manually? Pin
led mike8-Oct-08 10:08
led mike8-Oct-08 10:08 
GeneralRe: How do I call the combobox SelectionChangeCommitted event manually? Pin
DaveyM698-Oct-08 11:50
professionalDaveyM698-Oct-08 11:50 
GeneralRe: How do I call the combobox SelectionChangeCommitted event manually? Pin
OldSchoolToC#8-Oct-08 10:17
OldSchoolToC#8-Oct-08 10:17 
QuestionArrayList vs. List&lt;object&gt; Pin
dbrenth8-Oct-08 5:28
dbrenth8-Oct-08 5:28 
AnswerRe: ArrayList vs. List<object></object> PinPopular
led mike8-Oct-08 5:39
led mike8-Oct-08 5:39 
GeneralRe: ArrayList vs. List Pin
Dave Kreskowiak8-Oct-08 8:29
mveDave Kreskowiak8-Oct-08 8:29 
GeneralRe: ArrayList vs. List Pin
led mike8-Oct-08 10:02
led mike8-Oct-08 10:02 
AnswerRe: ArrayList vs. List&lt;object&gt; Pin
Simon P Stevens8-Oct-08 5:41
Simon P Stevens8-Oct-08 5:41 
GeneralRe: ArrayList vs. List&lt;object&gt; Pin
dbrenth8-Oct-08 5:44
dbrenth8-Oct-08 5:44 
GeneralRe: ArrayList vs. List&lt;object&gt; Pin
Mark Salsbery8-Oct-08 7:35
Mark Salsbery8-Oct-08 7:35 
AnswerRe: ArrayList vs. List&lt;object&gt; Pin
DaveyM698-Oct-08 5:43
professionalDaveyM698-Oct-08 5:43 
AnswerRe: ArrayList vs. List&lt;object&gt; Pin
Scott Dorman8-Oct-08 7:38
professionalScott Dorman8-Oct-08 7:38 
AnswerRe: ArrayList vs. List&lt;object&gt; Pin
Daniel Grunwald8-Oct-08 8:11
Daniel Grunwald8-Oct-08 8:11 
AnswerRe: ArrayList vs. List&lt;object&gt; Pin
CPallini8-Oct-08 9:15
mveCPallini8-Oct-08 9:15 

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.