S
Shirin14
Guest
Hello,
I am trying to retrive data from excel sheet based on a query , I have stored the excel sheet in an ODBC Driver.
The Query is : "select Newvalue from [Sheet1$] where Oldvalue='" + value + "'"
It works fine if the value which i am passing as old value is a string eg.abc , it returns an appropriate New Value for the old value passed from the excel sheet However, the Problem arises when the value passed is an integer value eg.757869
I get error on this lines
if (readData.HasRows) and while (readData.Read())
Below is the code which I have written:
OdbcConnection connectExcel = null;
connectionStringExcel = "DSN=abc;
try
{
connectExcel = new OdbcConnection(connectionStringExcel);
OdbcCommand DBCommandExcel = connectExcel.CreateCommand();
/* OdbcCommand*/
DBCommandExcel = new OdbcCommand("select NewId from [Sheet1$] where OldId='" + value + "'", connectExcel);
connectExcel.Open();
DBCommandExcel.ExecuteNonQuery();
try
{
OdbcDataAdapter adapter = new OdbcDataAdapter();
OdbcDataReader readData = DBCommandExcel.ExecuteReader();
int fCount = readData.FieldCount;
if (readData.HasRows)
{
while (readData.Read())
{
for (int i = 0; i < readData.FieldCount; i++)
{
id= readData.GetValue(i).ToString();
}
}
}
Thankyou
Continue reading...
I am trying to retrive data from excel sheet based on a query , I have stored the excel sheet in an ODBC Driver.
The Query is : "select Newvalue from [Sheet1$] where Oldvalue='" + value + "'"
It works fine if the value which i am passing as old value is a string eg.abc , it returns an appropriate New Value for the old value passed from the excel sheet However, the Problem arises when the value passed is an integer value eg.757869
I get error on this lines
if (readData.HasRows) and while (readData.Read())
Below is the code which I have written:
OdbcConnection connectExcel = null;
connectionStringExcel = "DSN=abc;
try
{
connectExcel = new OdbcConnection(connectionStringExcel);
OdbcCommand DBCommandExcel = connectExcel.CreateCommand();
/* OdbcCommand*/
DBCommandExcel = new OdbcCommand("select NewId from [Sheet1$] where OldId='" + value + "'", connectExcel);
connectExcel.Open();
DBCommandExcel.ExecuteNonQuery();
try
{
OdbcDataAdapter adapter = new OdbcDataAdapter();
OdbcDataReader readData = DBCommandExcel.ExecuteReader();
int fCount = readData.FieldCount;
if (readData.HasRows)
{
while (readData.Read())
{
for (int i = 0; i < readData.FieldCount; i++)
{
id= readData.GetValue(i).ToString();
}
}
}
Thankyou
Continue reading...