formatting in sql server
Please support our MS SQL advertiser: Programming Forums
Thread Solved
![]() |
•
•
Posts: 37
Reputation:
Solved Threads: 0
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:
I hope you understand what I mean and that you can help?
Kischi
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:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Common;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string excelConnectionString = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;""", Server.MapPath("database.xls"));
using (OleDbConnection connection =
new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand
("Select * FROM [Sheet1$]", connection);
connection.Open();
using (DbDataReader dr = command.ExecuteReader())
{
string sqlConnectionString = "Data Source=212.97.133.33;Initial Catalog=kischi2_database;UID=kischi2_radio;PWD=kischi;";
using (SqlBulkCopy bulkCopy =
new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "PROGRAM";
bulkCopy.WriteToServer(dr);
connection.Close();
}
}
}
}
}I hope you understand what I mean and that you can help?
Kischi
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
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
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
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
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
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
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
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
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
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Similar Threads
Other Threads in the MS SQL Forum
- How can show/view Infopath dynamic files(xml) without infopath in a computer (XML, XSLT and XPATH)
- C# and mycrosoft sql server 2k8? (C#)
- Backup of sql server using vb.net code (VB.NET)
- Problem in finding birthday from date of birth in SQL Server (MS SQL)
- The Definitive Guide to which Forum Software Information (Growing an Online Community)
- Special formatting of a GridView... (ASP.NET)
- How do you integrate a database w/web design? best solution for online catalogue? (Database Design)
Other Threads in the MS SQL Forum
- Previous Thread: Add SUM and AVG together also SUM and COUNT together
- Next Thread: mySQL UPDATE is adding erroneous spaces, special characters
•
•
•
•
Views: 1714 | Replies: 22 | Currently Viewing: 1 (0 members and 1 guests)






Linear Mode