Connecting Tech Pros Worldwide Help | Site Map

Kindly help in conversion of xls to grid

 
LinkBack Thread Tools Search this Thread
  #1  
Old February 7th, 2008, 06:18 AM
Needs Regular Fix
 
Join Date: Jan 2007
Posts: 353
Default Kindly help in conversion of xls to grid

Hello,

I have converted reading xls to sqlserver successfully.


Here's the code. Now I want slight modification in the below lines, I do not want the values Created By and Created Date from excel sheet. I want to these values to be inserted from the textbox. I tried out replacing the createdby and creteddate by textbox values, but could not succeed.

bulkCopy.ColumnMappings.Add("CreatedBy", "CreatedBy");
bulkCopy.ColumnMappings.Add("createddate", "CreatedDate");



Kindly Help

Regards

cmrhema

{
try
{
mycon.Open();
if (chooseuser == "Single")

string fname = FileUpload.PostedFile.FileName.ToString();

string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" "Data Source=" + fname + "; Extended Properties=Excel 8.0;";
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand();
OleDbDataAdapter dbcomm = new OleDbDataAdapter();
string strSelectString = "Select * FROM [Sheet1$]";
command = new OleDbCommand(strSelectString, connection);
dbcomm = new OleDbDataAdapter(strSelectString, connection);
connection.Open();

using (IDataReader dr = command.ExecuteReader())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(mycon))
{
bulkCopy.DestinationTableName = "ImportData";
bulkCopy.ColumnMappings.Add("CreatedBy", "CreatedBy");
bulkCopy.ColumnMappings.Add("createddate", "CreatedDate");
bulkCopy.ColumnMappings.Add("DownloadDate", "DownloadDate");
bulkCopy.ColumnMappings.Add("FileName", "FileName");
bulkCopy.ColumnMappings.Add("AccountNo/ChartNo", "Acc_ChartNo");
bulkCopy.ColumnMappings.Add("Billing/CaseNo", "Billing_CaseNo");
bulkCopy.ColumnMappings.Add("DOS", "DateOfService");
bulkCopy.ColumnMappings.Add("Provider", "Provider");
bulkCopy.ColumnMappings.Add("PatientName", "PatientName");
bulkCopy.ColumnMappings.Add("CPT", "CPT");
bulkCopy.ColumnMappings.Add("BilledAmount", "BilledAmount");
bulkCopy.ColumnMappings.Add("Copay", "Copay");
bulkCopy.ColumnMappings.Add("Users", "Users");
bulkCopy.ColumnMappings.Add("PostingDate", "PostingDate");
bulkCopy.WriteToServer(dr);
}
dr.Close();
}
connection.Close();
}
}
}
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.