public void UpdateGridViewProductType() { SqlConnection conn = new SqlConnection(dbconfig); SqlCommand cmd = null; SqlDataReader rdr = null; string sqlsel = "SELECT IdProductType as [Producttype Id], Name FROM ProductType"; try { conn.Open(); cmd = new SqlCommand(sqlsel, conn); rdr = cmd.ExecuteReader(); GridViewProductType.DataSource = rdr; GridViewProductType.DataBind(); } catch (Exception ex) { LabelMessageProductType.Text = ex.Message; } finally { conn.Close(); } }
private void UpdateGridViewProductType() { // Create a db connection with configuration from web.config SqlConnection conn = new SqlConnection(dbconfig); //SqlConnection conn = new SqlConnection(@"data source = .\SQLEXPRESS; integrated security = true; database = CMSdb"); SqlCommand cmd = null; SqlDataReader rdr = null; string sqlread = "SELECT IdProductType as [Producttype ID], Name FROM ProductType"; try { conn.Open(); cmd = new SqlCommand(sqlread, conn); rdr = cmd.ExecuteReader(); GridViewProductType.DataSource = rdr; GridViewProductType.DataBind(); } catch (Exception ex) { LabelProdType.Text = ex.Message; } finally { conn.Close(); } }