473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Unable to save the String data into a table from Excel sheet in SQL Server 2005 db

3
Hi all,

I am developing an application which reads an excel file which has the following records and inserts into a table in SQL SERVER 2005 database [Enterprise Edition].

Data:

Product Version CustType
------------- ------------- --------------
Norton SystemWorks Basic Edition 2009 CS
Norton 360 2 CS
Norton 360 2 CS
Norton SystemWorks Standard Edition 2009 CS
Norton AntiVirus 2009 CS
Norton Internet Security 2006 CS
Norton Internet Security 2008 CS
Norton SystemWorks 2006 CS
Norton 360 1 CS

This is code:

Expand|Select|Wrap|Line Numbers
  1.    Dim cn As New OleDbConnection
  2.         Dim dea As New OleDbDataAdapter
  3.         Dim dsee As New DataSet
  4.         Dim cea As String
  5.         Dim con1 As New OleDbConnection
  6.         Dim da1 As New OleDbDataAdapter
  7.         Dim da2 As New OleDbDataAdapter
  8.         Dim ds1 As New DataSet
  9.         Dim ds2 As New DataSet
  10.         Dim dt1 As New DataTable
  11.         Dim strOdbcCmdd As New OleDbCommand()
  12.         Dim iCnt As Integer = 0
  13.         Dim iCnt1 As Integer = 0
  14.         Dim straData(10) As String
  15.         Dim straData1(4) As String
  16.         Dim strSqlQry As String = String.Empty
  17.         Dim strOdbcCmd As New OleDbCommand()
  18.         cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & TextBox1.Text & ";" & "Extended Properties=Excel 8.0")
  19.         cn.Open()
  20.         cea = "select * from [Sheet1$]"
  21.         dea = New OleDbDataAdapter(cea, cn)
  22.         dea.Fill(dsee, "xls")
  23.         con1 = New OleDbConnection("Provider=SQLNCLI;Server=APP-GMF14-2K-D;Database=tempdb;Uid=sa;Pwd=Iseva123")
  24.         con1.Open()
  25.         Dim objstr(14) As String
  26.         Dim cnt As Integer = 0
  27.         For i As Integer = 0 To dsee.Tables("xls").Rows.Count - 1
  28.             strSqlQry = "Insert into test(product,version,custsubtype) values('" & dsee.Tables("xls").Rows(i).Item(0) & "','" & dsee.Tables("xls").Rows(i).Item(1) & "','" & dsee.Tables("xls").Rows(i).Item(2) & "')"
  29.             MsgBox(strSqlQry)
  30.             strOdbcCmd.CommandText = strSqlQry
  31.             strOdbcCmd.Connection = con1
  32.             strOdbcCmd.ExecuteNonQuery()
  33.             strSqlQry = ""
  34.         Next
  35.         MsgBox("Inserted " & dsee.Tables("xls").Rows.Count & " records !!")
  36.         cn.Close()
  37.         con1.Close()
But I am unable to capture the second column data if it is a string like "Basic Edition 2009" which shows Null or blank like:

Table Test:

ID Product Version CustType
--------------------------------------------------------------------
1 Norton SystemWorks <NULL> CS
2 Norton 360 2 CS
3 Norton 360 2 CS
4 Norton SystemWorks <NULL> CS
5 Norton AntiVirus 2009 CS
6 Norton Internet Security 2006 CS
7 Norton Internet Security 2008 CS
8 Norton SystemWorks 2006 CS
9 Norton 360 1 CS


How to make the string data read?
Oct 7 '08 #1
0 1041

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

Similar topics

8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
1
by: Abhijeet Kumar | last post by:
Hello I am exporting data to Excel from my .net Application using ISAM(Jet). I want to delete all record in the sheet before exporting. Since ISAM does not support Delete Operation. I am trying to...
0
by: I Decker | last post by:
Hi all, Hope this is the right group. I am writing a program in c# to open create an excel document, enter some data, save it and then email it as an attachment. I have successfully created...
0
by: isis5 | last post by:
i am using c# to parse some excel files to oracle.these files are created by an automated 3rd party process and we have no control over the naming convention and the version is excel 4.0 and the...
0
by: Vader | last post by:
I am new to this forum. Thanks in advance for and help. The following is what I am looking for: 1. I need help with VB code to open a MS Word (.doc) file. 2. Read lines from the MS Word (.doc)...
2
by: chike_oji | last post by:
Please can someone help me. I am writing a web application, that allows for the upload of an excel sheet into the database. I have an upload button and a save button. The upload button allows...
4
by: alvinstraight38 | last post by:
Hey guys, I am trying to import data from an Excel spreadsheet into my SQL database. I am running SQL 2005. I following Microsoft's instructions for creating a linked server, and it appeared...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
3
by: evenlater | last post by:
I have an Access application on a terminal server. Sometimes my users need to export reports to pdf, rtf or xls files and save them to their own client device hard drives. They can do that right...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
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...

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.