Thanks you,
But I want design an Program C# use Interface.
Today I writen Program but I think it have Problem,
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 Testinsertdata
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string excelFilePath;
if (txtopen.Text.Length > 0)
{
try
{
excelFilePath = txtopen.Text;
string sExcelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFilePath + ";Extended Properties=" + "\"Excel 8.0;HDR=YES;\"";
string sSqlConnectionString = "SERVER=.;USER ID=sa;PASSWORD=;DATABASE=EQMT_Database;CONNECTION RESET=FALSE";
OleDbConnection OleDbConn = new OleDbConnection(sExcelConnectionString);
OleDbConn.Open();
OleDbDataAdapter OA = new OleDbDataAdapter("SELECT * FROM [Tbl_EQMT$]", OleDbConn);
DataSet Ods = new DataSet();
DataTable Odt = new DataTable();
OA.Fill(Odt);
DataRow Orow;
SqlConnection SqlConn = new SqlConnection(sSqlConnectionString);
SqlConn.Open();
SqlDataAdapter Sda = new SqlDataAdapter("Select * from Tbl_EQMT", SqlConn);
DataTable Sdt = new DataTable();
SqlCommand Scm = new SqlCommand();
Scm.Connection = SqlConn;
Scm.CommandType = CommandType.Text ;
Sda.Fill(Sdt);
int Snum = Sdt.Rows.Count;
DataRow Srow;
for (int i = 0; i <= Odt.Rows.Count-1; i++)
{
for (int j = 0; j <= Odt.Columns.Count-1; j++)
{
Scm.CommandText = "Insert into Tbl_EQMT (" + Sdt.Columns[j].ColumnName.Trim() + ") values ( '" + Odt.Rows[i].ItemArray.GetValue(j) + "')";
Scm.ExecuteNonQuery();
}
}
MessageBox.Show("Success full");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
else{MessageBox.Show("You not Select Excel File Excel","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);}
}
private void btopen_Click(object sender, EventArgs e)
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Excel files|*.xls|Excel files (*.xls)|*.xls";
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
if (dialog.FileName.Length > 0)
{
txtopen.Text = dialog.FileName;
}
}
catch
{
MessageBox.Show("File Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
this.Cursor = System.Windows.Forms.Cursors.Default;
}
}
}
Pls, help me redisign it.