AboutNick Expertise I can answer questions regarding C#, C , SQL, Visual Basic, .Net Framework 2.0, general programming technique, and general algorithm development. My current area of focus is C#.
Experience C /VB programmer since 10th grade. I used to love video game development (still do, just don't do it anymore). Have real world experience in 3 companies for a total of about 2 years non-academic experience.
Organizations Keneisys (a security software company)
Education/Credentials BS in Computer Science with minor in Entertainment Technology.
Awards and Honors "The Next Bill Gates" gag award :-). College: Summa Cum Laude.
Expert: Nick Date: 2/8/2008 Subject: XLS to sql server
Question QUESTION: Hello,
Thanks for all the previous replies.
Kindly help me in the below
I have converted reading xls to sqlserver(through some forum) 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.
ANSWER: Just as a funny side note, when I was searching for some possible answers to your question, I found that you asked this question on another forum: http://www.thescripts.com/forum/thread768102.html
Hopefully they will get back to you before I do :-P
To be honest, this is not my area of expertise. However, I can search for an answer given a little more information. It seems like you are trying to copy data from an excel spreadsheet and insert it into an SQL database table. From what you explained, it is clear that you do not want the "Created By" and "Created Date" to come from the Excel spreadsheet. However, I am not certain where you do want them to come from. You said you want them to come from a textbox, but I am not sure what textbox you mean. Do you mean a textbox on a Windows Form you have created? Perhaps you mean a textbox in another Excel spreadsheet? Do you want a single value to be used for each "Created By" column and another single value to be used for each "Created Date" column? Or, do you want the user to be able to enter a new value for each different column? As you can see, I am a little unsure of exactly what you want, which makes it hard to answer your questions. However, I'll give a few tries below.
For one, I noticed "createddate" has no upper case letters in it, although every other value listed does. Is this case senstive? If so, perhaps that could be your problem.
Also, is it necessary to use bulk copy to perform these operations? Perhaps you could perform the operations on individual columns. I've had experience with doing operations on individual columns and could probably help you out with inserting custom values using that method.
If none of that helps, give me some more details and I may be able to assist you further.
---------- FOLLOW-UP ----------
QUESTION: Hello Nick,
None replied in the forums.The createdby will be the login name which will be typed in the textbox(web application).
and similarly they will be entering the date in textbox.
These two values will NOT BE provided in the excel sheet.
Hence we are stuck in the process.
I have put forward this question in thescripts.com too.
But no answer
Regards
Hemalatha
Answer I still don't completely understand your question. However, I created some code that illustrates, in a simple manner, how to insert custom values into an SQL table from C#. First, you must get whatever values you need from your Excel source. Then, you will connect to the SQL database. Then, you will create a series of commands that insert each row into the SQL database. The row will be comprised of whatever data you like (some of it can come from the Excel data source and some can come from the value entered by the user into the textbox). For the moment, I am assuming you know how to get the data from the Excel data source. Here is the code that inserts data into an SQL table (obviously, you will have to make modifications to suit your needs):