Re: executing sql query from inline C#

Home Page Forums BizTalk 2004 – BizTalk 2010 executing sql query from inline C# Re: executing sql query from inline C#

#23611

You can create a method with the following. But this is for SQL server database. You need to change the interfaces for oracle database

 

//Write the Query

string sqlQuery = “SELECT * FROM table WHERE condition”;

string connectionString = Common.GetAppSetting(SERVER_CONNECTION);

//connect to database

SqlConnection connection = new SqlConnection(connectionString);

 

//run the SQL query

SqlCommand sqlComm = new SqlCommand(sqlQuery, connection);

SqlParameter myParam = new SqlParameter();

myParam.ParameterName = “@mydate”;

myParam.Value = DateTime;

sqlComm.Parameters.Add(myParam);

sqlComm.Connection.Open();

ArrayList recordList = new ArrayList();

SqlDataReader reader = sqlComm.ExecuteReader();

// add data to Array List

while (reader.Read())

{

object[] values = new object[reader.FieldCount];

reader.GetValues(values);

Employee employee = new Employee();

employee.EmployeeID = values[0].ToString();

employee.Guid = Guid.NewGuid().ToString();

recordList.Add(employee);

}

sqlComm.Connection.Close();

return recordList;