magritton
4/24/2014 - 2:14 PM

Simple Database read in ASP.NET

Simple Database read in ASP.NET

using System.Data;
using System.Data.SqlClient;

string strConnectionString = @"Password=FaY5FEC5;Persist Security Info=True;User ID=OPWDataWriter;Initial Catalog=OPWBI;Data Source=opwsql03\sp2013tabular";
            string strQuery = "SELECT * FROM OPWCustomerService.OPWNewCustomer WHERE ItemKey = '" + strID + "'";
            SqlConnection sc = new SqlConnection(strConnectionString);

            SqlCommand queryCommand = new SqlCommand(strQuery, sc);
            sc.Open();
            SqlDataReader dr = queryCommand.ExecuteReader();

            DataTable dt = new DataTable();
            dt.Load(dr);
            foreach (DataRow item in dt.Rows)
            {
                txtItemKey.Text = item.Field<string>("ItemKey");
                txtDeniedPersons.Text = item.Field<string>("DeniedPersonsNotes");
                chkDeniedPersons.Checked = item.Field<int>("DeniedPersonsCompleted") == 1 ?  true : false;
                txtSpeciallyDesignaated.Text = item.Field<string>("SpeciallyDesignatedNotes");
                chkSpeciallyDesignaated.Checked = item.Field<int>("SpeciallyDesignatedCompleted") == 1 ? true : false;
                txtDebarredParty.Text = item.Field<string>("DebarredPartyNotes");
                chkDebarredParty.Checked = item.Field<int>("DebarredPartyCompleted") == 1 ? true : false;
                txtNonPiliforation.Text = item.Field<string>("NonProliferationNotes");
                chkNonPiliforation.Checked = item.Field<int>("NonProliferationCompleted") == 1 ? true : false;
                cboAcceptance.SelectedIndex = item.Field<int>("CompanyAccept");
                txtStatus.Text = "Update";//item has been found, flag has been set
            }