Hi I am completely new in ASP.net, I tried to use one code that suresh has posted in this forum earlier with little change but having bellow errors.
Code I have used:
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partialclass_Default : System.Web.UI.Page
{
privateString strConnection ="Data Source=SENPWM10519387\\SQLEXPRESS;Initial Catalog=QATest;Integrated Security=True";
protectedvoid Page_Load(object sender, EventArgs e)
{
}
protectedvoid btnSend_Click(object sender, EventArgs e)
{
//file upload path
string path = fileuploadExcel.PostedFile.FileName;
/Import Data Type check
string ddlValue = ddlImportType.SelectedValue;
//Create connection string to Excel work book
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ path +";Extended Properties=Excel 12.0;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection =newOleDbConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
if (ddlValue ='DUComp')
{
OleDbCommand cmd = newOleDbCommand("Select [Deployment Unit],[Deployment Scenario],[Wave Plan], [User ID], [Country], [Computer Name (Old)], [New Computer Type], [New Tag], [Application Readiness] from [Deployment Unit Computer$]", excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = newSqlBulkCopy(strConnection);
//Give your Destination table name
sqlBulk.DestinationTableName ="DUComputer";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
}
elseif (ddlValue = 'DUApp')
{
OleDbCommand cmd = newOleDbCommand("Select [User ID], [Application], [Status], [Computer Name (Old)], [Package-ID] from [Deployment Unit Apps$]", excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = newSqlBulkCopy(strConnection);
//Give your Destination table name
sqlBulk.DestinationTableName ="DUApplications";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
}
else
{
}
}
}
Design Page:--------------------------------------------------------------------------------------------------------------------------------------
<%@PageLanguage="C#"AutoEventWireup="true" CodeFile="Default.aspx.cs"Inherits="_Default" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headid="Head1"runat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<table>
<tr>
<td>
<spanstyle="color: Red">*</span>Select Import Data Type
</td>
<td>
<asp:DropDownListID="ddlImportType"runat="server"AutoPostBack="true">
<asp:ListItemText="--Select Import Type--"Selected="True"></asp:ListItem>
<asp:ListItemText="Deployment Unit Computers"Value="DUComp"></asp:ListItem>
<asp:ListItemText="Deployment Unit Applications"Value="DUApp"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<spanstyle="color: Red">*</span>Attach Excel file
</td>
<td>
<asp:FileUploadID="fileuploadExcel"runat="server"/>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:ButtonID="btnSend"runat="server"Text="Export"onclick="btnSend_Click" />
</td>
</tr>
</table>
<asp:GridViewID="GridView1"runat="server">
</asp:GridView>
</div></form>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------------------------------
Compilation Error
Description:An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1012: Too many characters in character literal
Source Error:
Line 32: //Create OleDbCommand to fetch data from Excel
Line 33: Line 34: if (ddlValue ='DUComp') |