473,508 Members | 2,140 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 19518
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
7786
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:...
1
2089
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. ...
1
2384
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...
1
2311
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
2021
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
6401
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...
1
1359
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 ...
1
10386
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...
2
4927
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...
1
2147
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...
0
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7332
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
7393
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
7502
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
5635
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,...
1
5057
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...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
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 ...
0
426
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...

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.