Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old February 7th, 2008, 07:18 AM
Needs Regular Fix
 
Join Date: Jan 2007
Posts: 305
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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 network members.
Post your question now . . .
It's fast and it's free

Popular Articles