473,569 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Kindly help in conversion of xls to grid

375 Contributor
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.Column Mappings.Add("C reatedBy", "CreatedBy" );
bulkCopy.Column Mappings.Add("c reateddate", "CreatedDat e");



Kindly Help

Regards

cmrhema

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

string fname = FileUpload.Post edFile.FileName .ToString();

string excelConnection String = @"Provider=Micr osoft.Jet.OLEDB .4.0;" "Data Source=" + fname + "; Extended Properties=Exce l 8.0;";
using (OleDbConnectio n connection = new OleDbConnection (excelConnectio nString))
{
OleDbCommand command = new OleDbCommand();
OleDbDataAdapte r dbcomm = new OleDbDataAdapte r();
string strSelectString = "Select * FROM [Sheet1$]";
command = new OleDbCommand(st rSelectString, connection);
dbcomm = new OleDbDataAdapte r(strSelectStri ng, connection);
connection.Open ();

using (IDataReader dr = command.Execute Reader())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(myc on))
{
bulkCopy.Destin ationTableName = "ImportData ";
bulkCopy.Column Mappings.Add("C reatedBy", "CreatedBy" );
bulkCopy.Column Mappings.Add("c reateddate", "CreatedDat e");
bulkCopy.Column Mappings.Add("D ownloadDate", "DownloadDate") ;
bulkCopy.Column Mappings.Add("F ileName", "FileName") ;
bulkCopy.Column Mappings.Add("A ccountNo/ChartNo", "Acc_ChartN o");
bulkCopy.Column Mappings.Add("B illing/CaseNo", "Billing_CaseNo ");
bulkCopy.Column Mappings.Add("D OS", "DateOfService" );
bulkCopy.Column Mappings.Add("P rovider", "Provider") ;
bulkCopy.Column Mappings.Add("P atientName", "PatientNam e");
bulkCopy.Column Mappings.Add("C PT", "CPT");
bulkCopy.Column Mappings.Add("B illedAmount", "BilledAmount") ;
bulkCopy.Column Mappings.Add("C opay", "Copay");
bulkCopy.Column Mappings.Add("U sers", "Users");
bulkCopy.Column Mappings.Add("P ostingDate", "PostingDat e");
bulkCopy.WriteT oServer(dr);
}
dr.Close();
}
connection.Clos e();
}
}
}
Feb 7 '08 #1
0 1258

Sign in to post your reply or Sign up for a free account.

Similar topics

3
393
by: Alex Ayzin | last post by:
Hi, I have a column in my WinGrid, that's being populated with numeric data, but it's of String datatype(business rule requires to have these numbers as varchars in DB). On top of that, I need to be able to sort on that particular column. But because column contains character data(even though it looks like digits), the sorting is all out of...
11
1531
by: Diogo Alves - Software Developer | last post by:
Hi, I have a datagrid listing data from a database, and I am getting from the database real value (it's actually represents a total of minutes). What I want to do is Convert that number to a total of hours and minutes like this: on database: 70,5 on datagrid: 01:10:30
7
1417
by: Brian Henry | last post by:
Ok how do I fix this... it worked in ASP.NET 1.1, in 2.0 it says Error 3 Option Strict On disallows implicit conversions from 'Object' to 'String'. here is the part of code it is giving this error on, its an item template from a data grid... the line that has the error underlined is "<%#Eval("filename")%>" which use to be...
5
24705
by: Preben | last post by:
Hi, I get this error when trying to compile: -------- # g++ -c KGreyImage.cpp KGreyImage.cpp:25: error: expected constructor, destructor, or type conversion before '*' token --------
0
943
by: =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post by:
Hello, I have created my own simple ASP.NET expression. It looks like <%$ InstanceSettings:Name %>. It access NameValueCollection and returns string value. At the moment I need to convert this string to bool for one case because I use it to evalueate Visibility of column in templated grid view. I am trying to do something like this:...
0
2101
by: ronysk | last post by:
Hi, I am posting here to seek for help on type conversion between Python (Numeric Python) and C. Attachment A is a math function written in C, which is called by a Python program. I had studied SWIG and Python/C API a bit. I was able to pass numeric array (Numeric Python) into the C function and access/change these arrays. Problem I...
3
8583
by: Astley.lejasper | last post by:
Hi, I have a load of British National Grid references that I want to convert to decimal degrees so I can create a google KML file. Does anyone know of a module to do this? I've looked at http://pygps.org/#LatLongUTMconversion but am not really up to speed with projections and all this other mapping stuff. I want to take something like
6
7978
by: Romulo NF | last post by:
Greetings again to everyone, Im back to show this grid componenet i´ve developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data, call determined functions, and edit the data already present What will you need to use the grid? A table with standard markup and an ID to call the...
2
1288
by: poornimanithya76 | last post by:
Hi, i am tried to convert below piece of code from data grid to grid view. since grid view is not having item created event so i try to implement with row Created. i am unable to perform whole thing. protected void dg_ItemCreated(object sender, DataGridItemEventArgs e) { switch (e.Item.ItemType) {
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.