Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. retrieve check in data base

retrieve check in data base

Scheduled Pinned Locked Moved ASP.NET
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JAYRAJ GIRI
    wrote on last edited by
    #1

    SqlConnection cn = new SqlConnection(@""); string []Sel=new string[3]; int Cnt; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("Select * from color", cn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "color"); string d; for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { for (int j = 1; j <= ds.Tables[0].Columns.Count-1; j++) { d = ds.Tables[0].Rows[i].ItemArray[j].ToString(); Sel = d.Split(new Char[] { ',' }); Cnt = Sel.Length; switch (j) { case 1: { multchk(chk1, chk2, chk3, Sel); break; } case 2: { multchk(chk4, chk5, chk6, Sel); break; } } } } } protected void multchk(CheckBox ch1,CheckBox ch2,CheckBox ch3,string []str) { if (Cnt==1) { if (str[0] == "1") ch1.Checked = true; if (str[0] == "2") ch2.Checked=true; if (str[0] == "3") ch3.Checked = true; } if (Cnt==2) { if (str[0] == "1" || str[1] == "1") ch1.Checked = true; if (str[0] == "2" || str[1] == "2") ch2.Checked = true; if (str[0] == "3" || str[1] == "3") ch3.Checked = true; } if (Cnt==3) { if (str[0] == "1" || str[1] == "1" || str[2] == "1") ch1.Checked = true; if (str[0] == "1" || str[1] == "2" || str[2] == "3") ch2.Checked = true; if (str[0] == "1" || str[1] == "2" || str[2] == "3") ch3.Checked = true; } } protected void singchk(CheckBox ch1,CheckBox ch2,string []str) { if (str[0] == "1") ch1.Checked = true; if (str[1] == "2") ch2.Checked = true; }

    C 1 Reply Last reply
    0
    • J JAYRAJ GIRI

      SqlConnection cn = new SqlConnection(@""); string []Sel=new string[3]; int Cnt; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("Select * from color", cn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "color"); string d; for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { for (int j = 1; j <= ds.Tables[0].Columns.Count-1; j++) { d = ds.Tables[0].Rows[i].ItemArray[j].ToString(); Sel = d.Split(new Char[] { ',' }); Cnt = Sel.Length; switch (j) { case 1: { multchk(chk1, chk2, chk3, Sel); break; } case 2: { multchk(chk4, chk5, chk6, Sel); break; } } } } } protected void multchk(CheckBox ch1,CheckBox ch2,CheckBox ch3,string []str) { if (Cnt==1) { if (str[0] == "1") ch1.Checked = true; if (str[0] == "2") ch2.Checked=true; if (str[0] == "3") ch3.Checked = true; } if (Cnt==2) { if (str[0] == "1" || str[1] == "1") ch1.Checked = true; if (str[0] == "2" || str[1] == "2") ch2.Checked = true; if (str[0] == "3" || str[1] == "3") ch3.Checked = true; } if (Cnt==3) { if (str[0] == "1" || str[1] == "1" || str[2] == "1") ch1.Checked = true; if (str[0] == "1" || str[1] == "2" || str[2] == "3") ch2.Checked = true; if (str[0] == "1" || str[1] == "2" || str[2] == "3") ch3.Checked = true; } } protected void singchk(CheckBox ch1,CheckBox ch2,string []str) { if (str[0] == "1") ch1.Checked = true; if (str[1] == "2") ch2.Checked = true; }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      This is the worst code I've seen in a long time. SO many things wrong with it. If someone I paid wrote this, I'd fire them. In fact, there's no way I'd have hired them. Your checkboxes are called chk1, chk2, chk3, chk4, chk5, and chk6 ? Are you hoping for future outsourcing work on the basis that your code is unreadable ?

      JAS GIRI wrote:

      string d; for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { for (int j = 1; j <= ds.Tables[0].Columns.Count-1; j++) { d = ds.Tables[0].Rows[i].ItemArray[j].ToString();

      You create d outside the loop but only use it inside. you use <= x-1 instead of < x, you start j from 1 instead of 0 ( is that right ), you use i and j instead of meaningful names, what a mess.

      JAS GIRI wrote:

      protected void multchk(CheckBox ch1,CheckBox ch2,CheckBox ch3,string []str) { if (Cnt==1) { if (str[0] == "1") ch1.Checked = true; if (str[0] == "2") ch2.Checked=true; if (str[0] == "3") ch3.Checked = true; } if (Cnt==2) { if (str[0] == "1" || str[1] == "1") ch1.Checked = true; if (str[0] == "2" || str[1] == "2") ch2.Checked = true; if (str[0] == "3" || str[1] == "3") ch3.Checked = true; } if (Cnt==3) { if (str[0] == "1" || str[1] == "1" || str[2] == "1") ch1.Checked = true; if (str[0] == "1" || str[1] == "2" || str[2] == "3") ch2.Checked = true; if (str[0] == "1" || str[1] == "2" || str[2] == "3") ch3.Checked = true; } }

      The logic surrounding Cnt is poorly implemented. Again, it's like you're trying to write spaghetti code. Perhaps if you in one place posted your crappy code, some notes as to what you're trying to do, an explanation of the data you're using, why you can't use a checkboxlist, and what exactly this code does, as opposed to what you expect it to do, perhaps then someone who feels like doing your job for you, might have what they need in order to help. If you fail to do this in the next day, then I'd suggest you're beyond any sort of help, and should just give up.

      Christian Graus Driven to the arms of OSX by Vista.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups