Showing posts with label sheet. Show all posts
Showing posts with label sheet. Show all posts

Saturday, February 11, 2012

(URgent)Problem with excel File

Hi,

I am trying to import data from a spread sheet to a sql server database... and one of the cells contains which are numeric and only and some are alpha numeric also... but when i try to import them to Sql server i get a NULL in the cells where there is Alpha numeric characters...

I have also tried opening a new spread sheet and setting the format for that particular column and text then i just paste it and then saving,.. but when i try to upload the data i am getting an error (thru my asp.net website) Saying that

No value given for one or more required parameters.

Hope someone can help me solve this.....

Regards

Karen

You could probably use BCP.exe to get this done quickly. The process would be to save the excel file as a .csv, then strip off the headers, if you use tab as your columns separator and \n as your row terminator, then you should be able to bcp it in with the -c option and no further work. Otherwise, you might need to create a format file. More information on how to use BCP can be found in books online for bcp.exe.

Hope that helps,

John

|||

Have you tried using OPENROWSET?

|||

Whats that about.. The user has data in spread sheet and right now i have built a interface that the user can directly log in and upload the excel files and then it will transfer the data to the database.. it works fine if a particular column doesnt have alpha numeric characters..

Regards

Karen

|||

Check out the following KB articles

http://support.microsoft.com/kb/321686 - This address's possible methods for importing from Excel to SQL Sever

Also http://support.microsoft.com/kb/194124/EN-US/

This article directly address's the issue of "Excel Values Returned as NULL Using DAO OpenRecordset"

This sounds like the issue you are facing

Regards

Nadreck

(URgent)Problem with excel File

Hi,

I am trying to import data from a spread sheet to a sql server database... and one of the cells contains which are numeric and only and some are alpha numeric also... but when i try to import them to Sql server i get a NULL in the cells where there is Alpha numeric characters...

I have also tried opening a new spread sheet and setting the format for that particular column and text then i just paste it and then saving,.. but when i try to upload the data i am getting an error (thru my asp.net website) Saying that

No value given for one or more required parameters.

Hope someone can help me solve this.....

Regards

Karen

You could probably use BCP.exe to get this done quickly. The process would be to save the excel file as a .csv, then strip off the headers, if you use tab as your columns separator and \n as your row terminator, then you should be able to bcp it in with the -c option and no further work. Otherwise, you might need to create a format file. More information on how to use BCP can be found in books online for bcp.exe.

Hope that helps,

John

|||

Have you tried using OPENROWSET?

|||

Whats that about.. The user has data in spread sheet and right now i have built a interface that the user can directly log in and upload the excel files and then it will transfer the data to the database.. it works fine if a particular column doesnt have alpha numeric characters..

Regards

Karen

|||

Check out the following KB articles

http://support.microsoft.com/kb/321686 - This address's possible methods for importing from Excel to SQL Sever

Also http://support.microsoft.com/kb/194124/EN-US/

This article directly address's the issue of "Excel Values Returned as NULL Using DAO OpenRecordset"

This sounds like the issue you are facing

Regards

Nadreck

(urgent)Insert data from a excel Spread sheet to SQl server

Hi,

I have a spread sheet which has 4 columns called cusip, Chartheader, growthdates and NAV.. and i also have the same number of columns in the Sql server... and I want to add another column called Rownumber and set it as int indentity... and when i try to import the data to sql server i am getting this error called

Received an invalid column length from the bcp client for colid 1.

How should i fix it.

Regards

Karen

usual way is:

1). Import data from Excel sheet;

2). Change the column names, format data if necessary;

3). Add an identity column.

|||

Without the int indentity column the import works fine... The reason i want to add the row number to the table is becauase after i transfer it to a staging database i am scrubbing the data and then inserting it to another database. But in the process of transferring data from the staging database to the actual databse the dates get jumbled up and is not in the same order that it was in the staging database.. and because of that my data in a particular sub report is not right.. this is what i am doing... in my asp.net program

If (flGrowth10K.PostedFile.FileName.ToLower.EndsWith(".xls")Or flGrowth10K.PostedFile.FileName.ToLower.EndsWith(".csv"))Then flGrowth10K.PostedFile.SaveAs(location6)' Connection String to Excel WorkbookTry Dim excelConnectionStringAs String =String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0", location6)'"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=location;Extended Properties=Excel 8.0" ' Create Connection to Excel Workbook Using connectionAs Data.OleDb.OleDbConnection =New Data.OleDb.OleDbConnection(excelConnectionString)Dim commandAs Data.OleDb.OleDbCommand =New Data.OleDb.OleDbCommand("Select Cusip,FundName,ChartHeader,GrowthDates,GrowthNAV FROM [Sheet1$]", connection) connection.Open()' Create DbDataReader to Data Worksheet Using drAs Data.Common.DbDataReader = command.ExecuteReader()' SQL Server Connection StringDim sqlConnectionStringAs String = System.Configuration.ConfigurationManager.AppSettings(APPSETTINGS_CONNECTION)'"Data Source=.; Initial Catalog=Test;Integrated Security=True"Dim myconnectionAs New SqlConnection(System.Configuration.ConfigurationManager.AppSettings(APPSETTINGS_CONNECTION))Dim queryAs String ="Truncate Table Growth" myconnection.Open()Dim cmdAs New SqlCommand(query, myconnection) cmd.CommandType = CommandType.Text cmd.ExecuteScalar() myconnection.Close()' Bulk Copy to SQL Server Using bulkCopyAs SqlBulkCopy =New SqlBulkCopy(sqlConnectionString) bulkCopy.DestinationTableName ="Growth" bulkCopy.WriteToServer(dr)End UsingEnd Using connection.Close()End UsingCatch exAs ExceptionThrow exEnd Try End If Try oImportFunds =New ImportFunds(System.Configuration.ConfigurationManager.AppSettings(APPSETTINGS_CONNECTION))With oImportFunds .PeriodID = ddlPeriod.SelectedItem.Value .save()End With Catch exAs Exception lblErrorMsg.Text ="Error: Import Failed" + ex.Message lblErrorMsg.Visible =True End Try

I was wondering if i have to add Rownumber to the select clause in the oledbstatement too...

any help will be appreciated

Regards

Karen

|||

I am sorry that I didn't know you did it in your application. The error happen, I think, because your excel columns don't match your table's columns (Your table column 1 is an identity integer data now. Your application tried to insert Cusipinto this first column). If I was you, I will let the program work first, then mannually add the identity column after data imported.

|||

Thanks for your suggestion... But i cannot do that cause everytime the user updates the tables using the spread sheets i cannot go in add the row number. The reason is we have given full access to that co. to use our database. .. is there a way to specify in the oledb statement that the first column is an int identity... something in the select statement. right now i dont have the Row number in my database... so it works fine.. but on some imports things get imported as it is in the staging database and some some entries get jumbled up.

Regards

Karen

|||

Just curious(I doubt it will work) to see what happens if you change your SELECT to "Select 0, Cusip,FundName,ChartHeader,GrowthDates,GrowthNAV FROM [Sheet1$]"

|||

che3358,

I think so it worked the way u told me to do...any ways let me update my dbase and try running it from a different server...

and will let u know the results.//

Regards

Karen

|||

here's a quick and dirty way to do it, suitable for a one-time solution:

copy the table definition (less the identify and timestamp columns) and create a new table, temp_whatever

Make sure the column order in the table matches the column order in the spreadsheet.

Open the table in sql server manager.

Copy the data in the spreadsheet, minus column headings.

Paste it into the temp table.

use this statement, adjusting for table and column names, and ignoring all identify and timestamp columns:

insert into real_table (col1name, col2name, col3name,...) select col1name, col2name, col3name, ... from temp_whatever.

when done, drop temp_whatever.

:)

(urgent)how should i treat signed decimal values in sql server

Hi,

I want to transfer the data from a excel spread sheet to sql server. I have used the oledb comand and it works fine, and i have also used the sqlbulkcopy and it transfers the data properly.

But in my excel spread sheet i have many columns with data as -0.76 or 0.76 or something like that but when it transfer it to sqlserver that particular column in sql server shows it as 0.00762711864406778

So how i can i tell sql server to display the data as 0.76 instead of 0.00762711864406778

any help will be appreciated.

Regards

Karen

Hi,

The only thing I can think of is the cells in excel with your decimal numbers is formated 1. to display 2 decimal places only, whilst the value is much more precise 2. (that's guess) cell is formated as percentage, so after convesion there is decimal point moved 2 places left ....

Hope at least one of these is true Smile

Tomek

|||

I changed the Format from Percentage to general but it still doesnt work.|||

So you've changed cell formating to general it shows in spreadsheet 0.76 and after transfer you get 0.00762711864406778

What db type has destination column, do you use vb(or any other language) or dts to transfer it?

Try to transfer it to flat file and then see which side cause problem.

Tomek

|||

I am using a oledb connection to connect to the excel spreadsheet and then using a sqlbulkcopy to copy it to sql server. Have changed the dbase field from varchar to money and when it was varchar i get 0.007627118464406778 in the db column and when i changed to money it is been stores as 0.0076

Regards

Karen

|||

This is strange, you changed the cell format from percentage to general and the cells still display 0.76? That seems wrong to me. When you change to general, it should change to .0076 right? So all we are left with as a mystery is why you only see .0076 and if you copy it over to SQL Server you see .0076.....otherstuff, right? Did you change it to "general" or "number"? Number and percentage have a box with "decimal places" in it, that specify how many decimal places to show, but general should show all of them up to the width of the box, the rest are truncated just like any other overflowing field. Is this what is happening? If you go to "number" and increase "decimal places" under formatting options to 10 or 50, does it show some of what SQL Server shows you?

If so, you should consider that Excel is different from SQL Server in that Excel is designed to be both front-end and database at the same time, so it understands the idea of truncating data on display implicitly while separately storing the truth. SQL Server does not implicitly do so, you would need to write a stored procedure or a query that explicitly rounds to see rounded numbers, so you might do 'SELECT round(column, 2.) from table' to get that rounding behavior that you desire. If you want a rounded table, meaning that the data itself is truncated, then you can write a quick t-sql statement to truncate the data in your table but that would affect the accuracy of any further calculations you do from that data.

Hope that helps,

John

|||

John,

Thanks for your answer, I am not doing any calculation for this field, it just gonna displayed in a report. so in the report i will multiply the field by 100 and that should give the right result.

Regards

Karen

(urgent)how should i treat signed decimal values in sql server

Hi,

I want to transfer the data from a excel spread sheet to sql server. I have used the oledb comand and it works fine, and i have also used the sqlbulkcopy and it transfers the data properly.

But in my excel spread sheet i have many columns with data as -0.76 or 0.76 or something like that but when it transfer it to sqlserver that particular column in sql server shows it as 0.00762711864406778

So how i can i tell sql server to display the data as 0.76 instead of 0.00762711864406778

any help will be appreciated.

Regards

Karen

You probably have the columns in excel formatted as a percentage column.

Multiply by 100 and round to the nearest .01

|||

the columns excel are in General, i have tried currency and number and text and they dont work

Regards

Karen