formatting in sql server

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2008
Posts: 37
Reputation: kischi is an unknown quantity at this point 
Solved Threads: 0
kischi kischi is offline Offline
Light Poster

formatting in sql server

 
0
  #1
Dec 22nd, 2008
Hi I have a problem when I am copying data from my excel document to sql server 2005.

I have a document called database.xls
Every time I try to copy files from the document to sql server.
It comes up with an error. "Column 'tid' does not allow DBNull.Value."

You can see the error on: http://www.excel.web.surftown.dk/ and then press the button.

but then when I check the rows in the database on "allow null", then it works fine. but it writes the time out like this 30-12-1899 12:00:00
instead of just 12:00:00 as I have written it in the excel file.

So how do I get the error to go away even though "allow null" is not checked?

My excel file looks like this:

id, tid, txt, dato
-----------------------------------
1, 12:00,dnwq, 23-12-2008
2, 14:00, aca, 23-12-2008


and my sql server table looks like this with the datatypes:

ID(bigint),
time(varchar(50),
txt(text),
date(datetime)

This is my code on the page for copying the excel to sql server:

  1. USING System;
  2. USING System.Collections.Generic;
  3. USING System.Linq;
  4. USING System.Web;
  5. USING System.Web.UI;
  6. USING System.Web.UI.WebControls;
  7. USING System.DATA.SqlClient;
  8. USING System.DATA;
  9. USING System.Configuration;
  10. USING System.Collections;
  11. USING System.Web.Security;
  12. USING System.Web.UI.WebControls.WebParts;
  13. USING System.Web.UI.HtmlControls;
  14. USING System.DATA.Common;
  15. USING System.DATA.OleDb;
  16.  
  17.  
  18.  
  19.  
  20. public partial class _Default : System.Web.UI.Page
  21. {
  22. protected void Page_Load(object sender, EventArgs e)
  23. {
  24.  
  25. }
  26.  
  27.  
  28. protected void Button1_Click(object sender, EventArgs e)
  29. {
  30. string excelConnectionString = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;""", Server.MapPath("database.xls"));
  31.  
  32.  
  33.  
  34. USING (OleDbConnection connection =
  35. new OleDbConnection(excelConnectionString))
  36. {
  37.  
  38. OleDbCommand command = new OleDbCommand
  39. ("Select * FROM [Sheet1$]", connection);
  40.  
  41. connection.Open();
  42.  
  43. USING (DbDataReader dr = command.ExecuteReader())
  44. {
  45. string sqlConnectionString = "Data Source=212.97.133.33;Initial Catalog=kischi2_database;UID=kischi2_radio;PWD=kischi;";
  46.  
  47. USING (SqlBulkCopy bulkCopy =
  48. new SqlBulkCopy(sqlConnectionString))
  49. {
  50. bulkCopy.DestinationTableName = "PROGRAM";
  51. bulkCopy.WriteToServer(dr);
  52.  
  53. connection.Close();
  54.  
  55.  
  56. }
  57. }
  58. }
  59. }
  60. }

I hope you understand what I mean and that you can help?

Kischi
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: formatting in sql server

 
0
  #2
Dec 23rd, 2008
I can't debug your code right now, but I recommend to transfer data from different data repositories to SQL Server is to use SQL Server Integration Service which in SQL Server Business Intelligence Studio. through it your can transfer\cleans\custom your data.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kischi is an unknown quantity at this point 
Solved Threads: 0
kischi kischi is offline Offline
Light Poster

Re: formatting in sql server

 
0
  #3
Dec 23rd, 2008
I really don't understand what you mean.
So I shouldn't use the code I have used or what?

Kischi
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: formatting in sql server

 
0
  #4
Dec 23rd, 2008
No, don't use this code at all, and turn into using SSIS.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kischi is an unknown quantity at this point 
Solved Threads: 0
kischi kischi is offline Offline
Light Poster

Re: formatting in sql server

 
0
  #5
Dec 23rd, 2008
Ok but how do I then copy data from an excel document into an sql server?

Kischi
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: formatting in sql server

 
0
  #6
Dec 23rd, 2008
Again, open SQL Server Business Intelligence Development Studio (Shipped with SQL Server all editions expect Express one), create project from type SQL Server Integration Services Project, select Data Flow tab and do it, if you face any problem tell me.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kischi is an unknown quantity at this point 
Solved Threads: 0
kischi kischi is offline Offline
Light Poster

Re: formatting in sql server

 
0
  #7
Dec 23rd, 2008
I don't think I have SQL Server Business Intelligence Development Studio I can only see microsoft sql server management studio express.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: formatting in sql server

 
0
  #8
Dec 23rd, 2008
Because you've Express Edition!!
open SQL Server Business Intelligence Development Studio (Shipped with SQL Server all editions expect Express one
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: formatting in sql server

 
0
  #9
Dec 23rd, 2008
Look, send me the Excel file and the table scheme you need to insert into on ramyamahrous@hotmail.com I'll debug your code.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kischi is an unknown quantity at this point 
Solved Threads: 0
kischi kischi is offline Offline
Light Poster

Re: formatting in sql server

 
0
  #10
Dec 23rd, 2008
Ok I sent it to you
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC