// for testing only
string masterpart = "SOME PART NUMBER";
// end testing value
// Connect to external (in this case SQL Server) database
System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(@”Provider=sqloledb; Data Source=server; Initial Catalog=Test; Integrated Security=SSPI;”);
// construct sql Select statement to retrieve data from external database.
string sqltext = “Select partnum,totalstock,descrip from Sales Where Partnum = ‘” + masterpart + “‘;”;
System.Data.OleDb.OleDbCommand com = new System.Data.OleDb.OleDbCommand(sqltext);
com.Connection = myConnection;
myConnection.Open();
System.Data.OleDb.OleDbDataReader myDataReader = com.ExecuteReader();
myDataReader.Read();
string res = myDataReader.ToString();
myConnection.Close();
return res;
This should give you a starting point for debugging your code. If your database connection and SQL string are correct, your sample should return your expected result. If you don't get your expected result, you may need to tweak your connection string or your SQL query.
Note - I haven't tested the above code, I just rewrote a piece of your original code into a smaller test.
Eli
// for testing only
string masterpart = "SOME PART NUMBER";
// end testing value
// Connect to external (in this case SQL Server) database
System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(@”Provider=sqloledb; Data Source=server; Initial Catalog=Test; Integrated Security=SSPI;”);
// construct sql Select statement to retrieve data from external database.
string sqltext = “Select partnum,totalstock,descrip from Sales Where Partnum = ‘” + masterpart + “‘;”;
System.Data.OleDb.OleDbCommand com = new System.Data.OleDb.OleDbCommand(sqltext);
com.Connection = myConnection;
myConnection.Open();
System.Data.OleDb.OleDbDataReader myDataReader = com.ExecuteReader();
myDataReader.Read();
string res = myDataReader.ToString();
myConnection.Close();
return res;
This should give you a starting point for debugging your code. If your database connection and SQL string are correct, your sample should return your expected result. If you don't get your expected result, you may need to tweak your connection string or your SQL query.
Note - I haven't tested the above code, I just rewrote a piece of your original code into a smaller test.
Eli
Copyright © 2025 Aras. All rights reserved.