13
Answers

Need to import data from excel to SQL

Need to read excel data from the server folder path and update it in the SQL server .once it is updated need to move to another folder using the C# console application

code:   

string value = "read";
string ConStr;
string HDR;
HDR = "YES";
ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
    + fileFullPath + ";Extended Properties=\"Excel 12.0;HDR=" + HDR + ";IMEX=0\"";
OleDbConnection conn = new OleDbConnection(ConStr);
conn.Open();
OleDbCommand newvalues = new OleDbCommand("select * from [" + value + "$]", conn);
OleDbDataAdapter newvalue = new OleDbDataAdapter(newvalues);
DataTable dt = new DataTable();
dt.Fill(dt1);
conn.Close();
DataTable dt = dt1;
SqlCommand cmd = new SqlCommand("spupdate", connect);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter valparam = new SqlParameter("@update", SqlDbType.Structured);
valparam.TypeName = "tablevalue";
valparam.Value = values;
cmd.Parameters.Add(valparam);
cmd.ExecuteNonQuery();
connect.Close();

Answers (13)