G
Guest
Hello. I perform a search on a vfp table using select statement. Based on
the input paramter, the db engine performs a lookup by stripping the dashes
(-) from the searched string. The data in table is bad and I must remove
dashes. I use STRTRAN function. Now I have built commandText to select data
based on input parameter, as follows:
public DataTable GetAccountNumber(string Ssn)
{
//initialize objects
OleDbCommand oleXcmd = new OleDbCommand();
OleDbParameter oleParam = new OleDbParameter();
OleDbDataAdapter oleXda = new OleDbDataAdapter();
DataTable retVal = new DataTable();
try
{
oleXcmd.CommandText = "Select AcctNbr FROM Accounts.dbf ";
oleXcmd.CommandType = CommandType.Text;
oleParam = oleXcmd.Parameters.Add("@Ssn", OleDbType.VarChar, 9);
oleParam.Value = Ssn;
oleXcmd.CommandText += " WHERE STRTRAN(A.Ssn,[-],[]) = [@Ssn]";
oleXda.SelectCommand = oleXcmd;
oleXcmd.Connection = Connection;
// Execute the query
oleXda.Fill(retVal);
}
catch
.....
.....
If I hard-code value instead of passing the param, I return a value from
datatable. If using params, code executes but does not return any rows.
Oh yeah one more thing...I try to remove brackets surrounding param but C#
throws exception when the fill method is executed. So, my problem is that
parameter is not being evaluated.
the input paramter, the db engine performs a lookup by stripping the dashes
(-) from the searched string. The data in table is bad and I must remove
dashes. I use STRTRAN function. Now I have built commandText to select data
based on input parameter, as follows:
public DataTable GetAccountNumber(string Ssn)
{
//initialize objects
OleDbCommand oleXcmd = new OleDbCommand();
OleDbParameter oleParam = new OleDbParameter();
OleDbDataAdapter oleXda = new OleDbDataAdapter();
DataTable retVal = new DataTable();
try
{
oleXcmd.CommandText = "Select AcctNbr FROM Accounts.dbf ";
oleXcmd.CommandType = CommandType.Text;
oleParam = oleXcmd.Parameters.Add("@Ssn", OleDbType.VarChar, 9);
oleParam.Value = Ssn;
oleXcmd.CommandText += " WHERE STRTRAN(A.Ssn,[-],[]) = [@Ssn]";
oleXda.SelectCommand = oleXcmd;
oleXcmd.Connection = Connection;
// Execute the query
oleXda.Fill(retVal);
}
catch
.....
.....
If I hard-code value instead of passing the param, I return a value from
datatable. If using params, code executes but does not return any rows.
Oh yeah one more thing...I try to remove brackets surrounding param but C#
throws exception when the fill method is executed. So, my problem is that
parameter is not being evaluated.