Get list of part ID and code values using ADO.NET

Hide Topic ContentsShow Topic Contents
    1. Script

This script requires version SP7 or above.

Script

// Header

WriteLine("Part Listing");

WriteLine("Id    Code");

string connectString = @"Provider=SQLNCLI10;Data Source=localhost;Database=Inspect;User Id=sa;Password=password;";

try

{

   using (var sql = new AdoSql(connectString))

   {

      sql.SetCommand("select part_id, code from parts", ATS.Shared.ADO.NET.CommandType.Text);

            

      if (sql.OpenDataset())

      {

         while (sql.Read())

         {

            int id;

            string code;

            

            sql.GetField(0, out id);

            sql.GetField(1, out code);

            

            WriteLine(string.Format("id = {0}, code = {1}", id, code));

         }

      }

      

      sql.CloseDataset();

   }

}

catch (Exception ex)

{

   WriteLine(ex.Message);

}

Can we improve this topic?