Click here to Skip to main content
16,004,919 members
Home / Discussions / C#
   

C#

 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 7:10
maxatlis27-Mar-09 7:10 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
fly90427-Mar-09 7:54
fly90427-Mar-09 7:54 
AnswerRe: Progmatically Creating TreeNodes and Child Nodes Pin
Ian Shlasko27-Mar-09 9:58
Ian Shlasko27-Mar-09 9:58 
GeneralRe: Progmatically Creating TreeNodes and Child Nodes Pin
maxatlis27-Mar-09 13:20
maxatlis27-Mar-09 13:20 
AnswerHow To: - Progmatically Creating TreeNodes and Child Nodes [Answer] Pin
maxatlis27-Mar-09 14:37
maxatlis27-Mar-09 14:37 
QuestionOracle + #C DataBase Picture Pin
E_Gold27-Mar-09 5:17
E_Gold27-Mar-09 5:17 
QuestionNew Line VS2005 Installer's BodyText Pin
jp2code27-Mar-09 5:12
professionaljp2code27-Mar-09 5:12 
Questiondatabase in sql Pin
Mangesh Tomar27-Mar-09 4:39
Mangesh Tomar27-Mar-09 4:39 
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 here i creat only one table 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 data 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: database in sql Pin
musefan27-Mar-09 4:47
musefan27-Mar-09 4:47 
GeneralRe: database in sql Pin
Mangesh Tomar27-Mar-09 5:41
Mangesh Tomar27-Mar-09 5:41 
GeneralRe: database in sql Pin
musefan27-Mar-09 5:48
musefan27-Mar-09 5:48 
QuestionCreating an .msg file Pin
MxIsMe27-Mar-09 2:56
MxIsMe27-Mar-09 2:56 
QuestionReceive "Now Playing" Song Information Pin
give.away27-Mar-09 2:52
give.away27-Mar-09 2:52 
AnswerRe: Receive "Now Playing" Song Information Pin
musefan27-Mar-09 4:52
musefan27-Mar-09 4:52 
GeneralRe: Receive "Now Playing" Song Information Pin
give.away27-Mar-09 5:01
give.away27-Mar-09 5:01 
GeneralRe: Receive "Now Playing" Song Information Pin
musefan27-Mar-09 5:09
musefan27-Mar-09 5:09 
GeneralRe: Receive "Now Playing" Song Information Pin
give.away27-Mar-09 5:39
give.away27-Mar-09 5:39 
GeneralRe: Receive "Now Playing" Song Information Pin
Eddy Vluggen27-Mar-09 5:16
professionalEddy Vluggen27-Mar-09 5:16 
GeneralRe: Receive "Now Playing" Song Information Pin
give.away27-Mar-09 5:33
give.away27-Mar-09 5:33 
GeneralRe: Receive "Now Playing" Song Information Pin
0x3c027-Mar-09 6:09
0x3c027-Mar-09 6:09 
QuestionRe: Receive "Now Playing" Song Information Pin
Eddy Vluggen27-Mar-09 8:19
professionalEddy Vluggen27-Mar-09 8:19 
GeneralRe: Receive "Now Playing" Song Information [modified] Pin
give.away27-Mar-09 14:29
give.away27-Mar-09 14:29 
GeneralRe: Receive "Now Playing" Song Information Pin
Eddy Vluggen28-Mar-09 0:48
professionalEddy Vluggen28-Mar-09 0:48 
GeneralRe: Receive "Now Playing" Song Information Pin
give.away28-Mar-09 3:15
give.away28-Mar-09 3:15 
GeneralRe: Receive "Now Playing" Song Information Pin
Eddy Vluggen28-Mar-09 4:38
professionalEddy Vluggen28-Mar-09 4:38 

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.