This is my Technical area of troubleshooting and learning new Programming skills and many more. Here you will find answers for many new technologies like asp.net 2.0/3.5,4.0 C# access, mysql, Amazon Webservice ,Sql-server, JD Edwards, SAS, Salesforce, APIs, MVC and many more. please visit & discuss.
Monday, October 14, 2013
Saturday, October 12, 2013
Friday, October 11, 2013
Working code for upload data from Excel to Sql-Server Using C#
Working code for upload data from Excel 2010 to SQL-Server 2008 , working code.
C# , ASP.Net 4.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Data.Common;
using System.Configuration;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ExcelContentType = "application/vnd.ms-excel";
string Excel2010ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
if (FileUpload1.HasFile)
{
//Check the Content Type of the file
if (FileUpload1.PostedFile.ContentType == ExcelContentType || FileUpload1.PostedFile.ContentType == Excel2010ContentType)
{
try
{
//Save file path
string path = string.Concat(Server.MapPath("~/File/"), FileUpload1.FileName);//Create this folder ib your project
//Save File as Temp then you can delete it if you want
FileUpload1.SaveAs(path);
string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", path);
// Create Connection to Excel Workbook
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection);
connection.Open();
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
{
string sqlConnectionString = ConnectionString;
// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "Tbl_YourTable";
bulkCopy.WriteToServer(dr);
Label5.Text = "The data has been exported successfully from Excel to SQL";
}
}
}
}
catch (Exception ex)
{
Label5.Text = ex.Message;
}
}
}
}
private string ConnectionString
{
get
{
string connectionString = ConfigurationManager.ConnectionStrings["connmy"].ConnectionString;
return connectionString;
}
}
}
Error HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add
run this
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
Tuesday, October 8, 2013
Run SSIS package from C# 4.0 VS 2010
Microsoft.SqlServer.Dts.Runtime.Wrapper.ApplicationClass app = new Microsoft.SqlServer.Dts.Runtime.Wrapper.ApplicationClass();
string packagePath = @"C:\Users\kumaraje\Documents\Test SSIS.dtsx";
Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSPackage100 package = app.LoadPackage(packagePath, true, null);
package.Execute();
Sunday, October 6, 2013
Subscribe to:
Posts (Atom)