hi i tried like this....
protected void btnSend_Click(object sender, EventArgs e)
{
String strConnection = "Data Source=E-3D34;Initial Catalog=Ektha;Integrated Security=True";
string path = fileuploadExcel.PostedFile.FileName;
//Create connection string to Excel work book
string excelConnectionString = "user id=sa;password=e@2013;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
//Create Connection to Excel work book
SqlConnection excelConnection =new SqlConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
SqlCommand cmd = new SqlCommand("Select [EmployeeID],[EmployeeNAME],[Designation],[Department],[DOJ],[DOR],[Monthly Salary],[Medical],[HRA],[Incentive],[Other All],[OT],[Gross Total],[PF],[ESI],[Advance],[Other Ded],[PT],[TDS-1],[Total Ded],[Net Amt] from [Sheet1$]",excelConnection);
excelConnection.Open();
SqlDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
//Give your Destination table name
sqlBulk.DestinationTableName = "PayDescription";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
}
but am getting the error as....can you please help me
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source Error:
Line 31: //Create OleDbCommand to fetch data from Excel
Line 32: SqlCommand cmd = new SqlCommand("Select [EmployeeID],[EmployeeNAME],[Designation],[Department],[DOJ],[DOR],[Monthly Salary],[Medical],[HRA],[Incentive],[Other All],[OT],[Gross Total],[PF],[ESI],[Advance],[Other Ded],[PT],[TDS-1],[Total Ded],[Net Amt] from [Sheet1$]",excelConnection);
Line 33: excelConnection.Open(); Line 34: SqlDataReader dReader;
Line 35: dReader = cmd.ExecuteReader();
manimala
Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator