Click here to Skip to main content
15,900,378 members
Home / Discussions / C#
   

C#

 
GeneralRe: Opening our windows application by double clicking a file... Pin
jaypatel51225-Mar-09 20:57
jaypatel51225-Mar-09 20:57 
QuestionControl background color/image Pin
Sandeep Kalra25-Mar-09 19:30
Sandeep Kalra25-Mar-09 19:30 
AnswerRe: Control background color/image Pin
Xmen Real 25-Mar-09 19:44
professional Xmen Real 25-Mar-09 19:44 
GeneralRe: Control background color/image Pin
Sandeep Kalra25-Mar-09 20:24
Sandeep Kalra25-Mar-09 20:24 
QuestionJavascript : Disable buttone Pin
Ramkithepower25-Mar-09 19:03
Ramkithepower25-Mar-09 19:03 
AnswerRe: Javascript : Disable buttone Pin
tech60325-Mar-09 19:24
tech60325-Mar-09 19:24 
AnswerRe: Javascript : Disable buttone Pin
Cracked-Down25-Mar-09 19:28
Cracked-Down25-Mar-09 19:28 
Questiondynamic table in data base Pin
Mangesh Tomar25-Mar-09 18:43
Mangesh Tomar25-Mar-09 18:43 
hi
This is my code in which i upload a excel file using file dialog box and store it in to the sql server as table name emp but problem is that when i run the program secound time all the values again store in same table
so my question is that is possible to create a table at run time in bata base NEED HELP or any logic regaring that.


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.Data.SqlClient;

namespace openfi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog FD = new OpenFileDialog();
FD.Filter = "Excel|*.xls";
if (FD.ShowDialog() == DialogResult.OK)
{
textBox1.Text = " " + FD.FileName;
}
string filename = textBox1.Text;
String connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + filename + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand selectCommand = new OleDbCommand("SELECT * FROM [sheet1$]", connection);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
dataAdapter.SelectCommand = selectCommand;
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
System.Data.DataTable dataTable = dataSet.Tables[0];
dataGridView1.DataSource = dataSet.Tables[0];
// textBox1.Text = "";
MessageBox.Show(dataGridView1.RowCount.ToString());
connection.Close();
}

private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog FD = new OpenFileDialog();
FD.Filter = "Excel|*.xls";
if (FD.ShowDialog() == DialogResult.OK)
{
textBox2.Text = " " + FD.FileName;
}
string filename = textBox2.Text;
String connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + filename + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand selectCommand = new OleDbCommand("SELECT * FROM [sheet1$]", connection);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
dataAdapter.SelectCommand = selectCommand;
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
System.Data.DataTable dataTable = dataSet.Tables[0];
dataGridView2.DataSource = dataSet.Tables[0];
// textBox1.Text = "";
MessageBox.Show(dataGridView2.RowCount.ToString());
connection.Close();

}

private void button3_Click(object sender, EventArgs e)
{
this.Close();
}

private void button4_Click(object sender, EventArgs e)
{

string constr="data source=MYSERVER;initial catalog=mo;integrated security=SSPI";


// string constr = "Datasource=Myserver;Initialcatlog=mo;Integrated security=SSPI";
SqlConnection sqcon = new SqlConnection(constr);
SqlCommand scmd = new SqlCommand();
sqcon.Open();
int i = 1;

while (i < (dataGridView1.Rows.Count)-2)

{
string istr = "insert into emp(Personnel_Area,EE_Grp,Employee_Group,ES_Grp)values('" + Convert.ToString(dataGridView1.Rows[i].Cells[0].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[1].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[2].Value.ToString()) + "','" + Convert.ToString(dataGridView1.Rows[i].Cells[3].Value.ToString()) + "')";
MessageBox.Show(istr);
scmd.CommandText = istr;
scmd.Connection = sqcon;
int r;
r = scmd.ExecuteNonQuery();
if (r > 0)
// MessageBox.Show("Record Saved");
i++;
}
if (i > 1)
{
MessageBox.Show("Records saved");
}



}
}
}
AnswerRe: dynamic table in data base Pin
tech60325-Mar-09 19:35
tech60325-Mar-09 19:35 
GeneralRe: dynamic table in data base Pin
dano2k325-Mar-09 22:28
dano2k325-Mar-09 22:28 
GeneralRe: dynamic table in data base Pin
Mangesh Tomar26-Mar-09 0:10
Mangesh Tomar26-Mar-09 0:10 
Question[Message Deleted] Pin
rpopple25-Mar-09 16:47
rpopple25-Mar-09 16:47 
AnswerRe: line number in a multiline edit window Pin
Xmen Real 25-Mar-09 19:46
professional Xmen Real 25-Mar-09 19:46 
AnswerRe: line number in a multiline edit window Pin
Henry Minute26-Mar-09 1:32
Henry Minute26-Mar-09 1:32 
Questionhow to browse a remote directory using ftp client Pin
T_Teef25-Mar-09 13:07
T_Teef25-Mar-09 13:07 
AnswerRe: how to browse a remote directory using ftp client Pin
ky_rerun25-Mar-09 16:56
ky_rerun25-Mar-09 16:56 
AnswerRe: how to browse a remote directory using ftp client Pin
logiclabz25-Mar-09 22:30
logiclabz25-Mar-09 22:30 
GeneralRe: how to browse a remote directory using ftp client Pin
T_Teef26-Mar-09 13:11
T_Teef26-Mar-09 13:11 
QuestionReflection ! Pin
Mohammad Dayyan25-Mar-09 11:29
Mohammad Dayyan25-Mar-09 11:29 
AnswerRe: Reflection ! Pin
DaveyM6925-Mar-09 11:35
professionalDaveyM6925-Mar-09 11:35 
GeneralRe: Reflection ! Pin
Mohammad Dayyan25-Mar-09 11:45
Mohammad Dayyan25-Mar-09 11:45 
GeneralRe: Reflection ! Pin
DaveyM6925-Mar-09 11:50
professionalDaveyM6925-Mar-09 11:50 
GeneralRe: Reflection ! Pin
Mohammad Dayyan25-Mar-09 11:53
Mohammad Dayyan25-Mar-09 11:53 
GeneralRe: Reflection ! Pin
DaveyM6925-Mar-09 12:31
professionalDaveyM6925-Mar-09 12:31 
GeneralRe: Reflection ! Pin
Luc Pattyn25-Mar-09 13:31
sitebuilderLuc Pattyn25-Mar-09 13:31 

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.