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
, 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
, I get "There is no row at position 0".
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
Code:
ds.Tables[0].Columns[0].ColumnName
When I run the query inside Access I receive the desired information. But when I try to check for the info in code
Code:
ds.Rows[0]
Code:
public DataTable FindFullPNusingPartialPN(string _parcelNumber) { OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ConfigurationManager.AppSettings["TaxCert_Database"]); DataTable dt = new DataTable(); try { string query = "SELECT ParcelNumber FROM Orders WHERE ParcelNumber LIKE '*" + _parcelNumber + "*';"; OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn); DataSet ds = new DataSet(); adapter.Fill(ds); if (ds.Tables[0].Rows.Count >= 0) { dt = ds.Tables[0]; } } catch (Exception ex) { throw; } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } return dt; }
Comment