473,414 Members | 1,980 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,414 software developers and data experts.

Problem while taking column values from Excel using vb.net

i am having one problem when i am retrieving data from Excel using vb.net

following is the code
Expand|Select|Wrap|Line Numbers
  1. Imports Microsoft.Office.Core
  2. Imports System.Runtime.InteropServices
  3. Imports System.Data.OleDb
  4. Public Class Form1
  5.     Dim cmd1 As OleDbCommand
  6.     Dim dr1 As OleDbDataReader
  7.     Dim str As String=" "
  8.     Try
  9.             cn = New 
  10.            OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data        
  11.            Source=C:\Folder\example_excel.xls;Extended Properties=Excel 8.0;")
  12.             'provider to be used when working with excel database
  13.             cn.Open()
  14.  
  15.             cmd1 = New OleDbCommand("select * from emp where 
  16.             rollno!="+str+"", cn)
  17.             MsgBox("1")
  18.             dr1 = cmd1.ExecuteReader()
  19.  
  20.         Catch
  21.         End Try
  22.  
when i am executing above code,i am getting error like
Syntax error (missing operator) in query expression 'rollno!='

i want to retrieve records with empty fields...
please help me in this problem...
Nov 24 '08 #1
2 1920
try 'rollNo <> '

!= is C# syntax for "not equals"

<> is SQL Query syntax for "not equal"

Also, put your code in code tags like the following, so it's easier to understand.

Expand|Select|Wrap|Line Numbers
  1. Imports Microsoft.Office.Core
  2. Imports System.Runtime.InteropServices
  3. Imports System.Data.OleDb
  4. Public Class Form1
  5. Dim cmd1 As OleDbCommand
  6. Dim dr1 As OleDbDataReader
  7. Dim str As String=" "
  8. Try
  9. cn = New
  10. OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
  11. Source=C:\Folder\example_excel.xls;Extended Properties=Excel 8.0;")
  12. 'provider to be used when working with excel database
  13. cn.Open()
  14.  
  15. cmd1 = New OleDbCommand("select * from emp where
  16. rollno!="+str+"", cn)
  17. MsgBox("1")
  18. dr1 = cmd1.ExecuteReader()
  19.  
  20. Catch
  21. End Try
  22.  
Nov 24 '08 #2
Plater
7,872 Expert 4TB
!= is still SQL syntax.
The problem looks to be that you are missing the first single quote ' after rollno!=
Nov 24 '08 #3

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

Similar topics

3
by: Jeremy | last post by:
Hi, I have a webpage that is taking input from a form and using it as criteria to select data out of an sql database. The page displays an html table with the results. The user can then click a...
19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
1
by: NancyA | last post by:
I am using the following code to write data from a datagrid to an Excel file: Dim tw As New System.IO.StringWriter Dim hw As New System.Web.UI.HtmlTextWriter(tw) dg.RenderControl(hw)...
5
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column...
8
by: Surya Dutt | last post by:
Hello, Did someone happen to come accross and algorithm or a C++ program that simulates the Smith Collge Diploma problem? "At Smith College, the graduation exercises traditionally proceed as...
11
by: The Frog | last post by:
Hi all, Maybe I am just missing something simple here, but I seem to have an issue with a callback function in A97 that is used to fill a Listbox with values. The first time the callback...
5
by: Narendar123P | last post by:
Hi all, I am trying to plot a graph in excel file using C#.Net. I am using the name space excel . If my graph has one series(2 columns), i am able to draw the graph. if my graph has two series(4...
2
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages...
3
by: MM | last post by:
Hi to all, I'm trying to import a tab separated values file onto Excel with the following script: import csv from pyExcelerator import * w = Workbook() worksheet = w.add_sheet('sim1')
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.