473,668 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filling in DataTable using OleDb

maylortaylor
72 New Member
For some reason I am having problems doing this simple task. I just want to run a query in Access to select a
a field from the table that is "like" the string being inputted.

However, the dataset comes back empty...well not empty, I get a column name but no data. So when I type in
Expand|Select|Wrap|Line Numbers
  1. ds.Tables[0].Columns[0].ColumnName
, I get the column name coming from the database ("ParcelNumber" ).

When I run the query inside Access I receive the desired information. But when I try to check for the info in code
Expand|Select|Wrap|Line Numbers
  1. ds.Rows[0]
, I get "There is no row at position 0".



Expand|Select|Wrap|Line Numbers
  1. public DataTable FindFullPNusingPartialPN(string _parcelNumber)
  2.             {
  3.                  OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ConfigurationManager.AppSettings["TaxCert_Database"]);                DataTable dt = new DataTable();
  4.                 try
  5.                 {
  6.                 string query = "SELECT ParcelNumber FROM Orders WHERE ParcelNumber LIKE '*" + _parcelNumber + "*';";
  7.  
  8.                 OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn);             
  9.  
  10.                 DataSet ds = new DataSet();
  11.                 adapter.Fill(ds);
  12.  
  13.  
  14.                 if (ds.Tables[0].Rows.Count >= 0)
  15.                 {
  16.                     dt = ds.Tables[0];
  17.                 }
  18.  
  19.                 }
  20.  
  21.                 catch (Exception ex)
  22.                 {
  23.                   throw;
  24.                 }
  25.                 finally
  26.                 {
  27.                     if (conn.State == ConnectionState.Open)
  28.                     {
  29.                         conn.Close();
  30.                     }
  31.                 }
  32.                 return dt;
  33.             }
Jul 2 '13 #1
1 19680
maylortaylor
72 New Member
Fixed it. Went with .Parameters and changed my "*" to "%".
Expand|Select|Wrap|Line Numbers
  1.  public DataTable FindFullPNusingPartialPN(string _parcelNumber)
  2.             {
  3.  
  4.                 string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ConfigurationManager.AppSettings["TaxCert_Database"];
  5.                 DataTable dt = new DataTable();
  6.  
  7.                 try
  8.                 {
  9.                     OleDbConnection conn = new OleDbConnection(connString);
  10.                     string query = "SELECT ParcelNumber FROM Orders WHERE ParcelNumber LIKE @_parcelNumber;";
  11.  
  12.                     OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn);
  13.                     adapter.SelectCommand.Parameters.Add("@_parcelNumber", OleDbType.VarChar).Value = "%" + _parcelNumber + "%";
  14.  
  15.                     DataSet ds = new DataSet();
  16.                     adapter.Fill(ds);
  17.  
  18.  
  19.                     if (ds.Tables[0].Rows.Count >= 1)
  20.                     {
  21.                         dt = ds.Tables[0];
  22.                     }
  23.  
  24.                 } 
  25.  
  26.  
  27.                 catch (Exception ex)
  28.                 {
  29.                     //myLogger.Log(ex.Message, ex.TargetSite.ToString(), ex.StackTrace);
  30.                     throw;
  31.                 }
  32.                 finally
  33.                 {
  34.                     //if (conn.State == ConnectionState.Open)
  35.                     //{
  36.                     //    conn.Close();
  37.                     //}
  38.                 }
  39.                 return dt;
  40.             }
Jul 2 '13 #2

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

Similar topics

4
7800
by: NS | last post by:
Hi, I am trying to execute a prepare statement using oledb provider for DB2. The command.Prepare() statement is giving me an exception " No error information available: DB_E_NOCOMMAND(0x80040E0C)." My code is very simple and is working with other oledb provider, like SQL Server and oracle.
1
2104
by: spicyz | last post by:
I'm receiving an exception when my webmethod exits after opening/closing an Access database. I can reproduce this easily enough by creating a new default ASP .NET Web Service in VS.NET 2003. Adding this code to the default HelloWorld() webmethod will cause the problem. String* sConnection = S"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=c:\\mydb.mdb";
1
2399
by: svijay | last post by:
hi I have got a strange problem. May I know any solution for this. Here is the detailed description about the problem We have got a mainframe system and also production and development server.
1
2316
by: pigeonrandle | last post by:
Quite simply, is this possible? I can only find information on DataTable.Select() It would be nice if it was :-) James Randle
0
2031
by: genojoe | last post by:
I have a 4 column, 6 row Excel sheet with all cells formatted for text: 1 1 a a 2 2 b b 3 3 c c a 4 d 1 b 5 e 2 c 6 f 3 I have the following schema.ini:
4
6411
by: Abel | last post by:
Hi I try to execute an sample how to read and write excel sheets using OleDb When opens the connection, the objConn.Open gave me this error: "Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." And appears the following message: System.Exception {System.Security.SecurityException} Any idea to solve this error? I work with VS...
1
1370
by: Muhamamd Khayyam | last post by:
I am passing a query to Oracle 9i using Oledb.command object. Code is Dim c As OleDb.OleDbCommand Dim sOURCE As BindingSource Dim DR As OleDb.OleDbDataReader Connect.Connect("scott", "tiger", "ORCL", "ORACLE") ' A module for connection string c = New OleDb.OleDbCommand("select * from EMP WHERE HIREDATE = '07-AUG-07', Connect.V_DbConnection) '' Connect.V_DbConnection is a connection object ...
1
10406
by: =?Utf-8?B?U2hlZXMgQWJpZGk=?= | last post by:
I read an article on the link: http://support.microsoft.com/default.aspx?scid=kb;en-us;306572 related to reading data from Excel using OLEDB The topic's heading is: How to query and display excel data by using ASP.NET, ADO.NET, and Visual C# .NET I am trying with the same code in Visual Studio 2005 in ASP.NET application. The code i am using is: protected void Page_Load(object sender, EventArgs e) { String connectionString...
2
4937
by: vasanth chandrasekaran | last post by:
Hai All, I try to insert the Dataset value in Exiting excel file by using OLEDB provider.But i face error messagge in objCmd.ExecuteNonQuery(); The error is :Syntax error in INSERT INTO statement.
1
2155
by: reshmajoshi | last post by:
Hi all, I am stucked up at this point. I searched alot on gooogle but didnot find anything. My problem is: I have an Excel file which i want to export to datatable and from datatable i want to save it to oracle DB. Excel file contains multiple columns and each column consists of large data(approx 20000characters/numbers). using oledbconnection(http://codehill.com/2009/01/reading-excel-2003-and-2007-files-using-oledb/),excel columns with such...
0
8459
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8791
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8575
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8653
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2784
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.