Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi guys!

I have this scenario:
1. Add first a checklist
2. Add activities to the Checklist created
3. Assign that checklist to a milestone

Now, I followed the instructions. I got a problem in creating the activity code where if there are more than one activity added to the checklist when assigning a milestone. Because when I assigned a milestone to a checklist, it will generate a checklist code for the checklist and at the same time, the activities that the checklist contained will generate activity code based from the checklist code plus the order number that it was added. But I got same activity code for every activities. Is it possible to make the activity code differ from the other activity?How can I make the activity code differ from one another?

Here is my code:

protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
   {
       connection();
       amicassaCon.Open();
       SqlCommand cmd = new SqlCommand("SELECT MAX(CAST(order_no as INT)) FROM checklists WHERE checklist_name='"+DropDownList2.SelectedValue+"'", amicassaCon);
       SqlDataReader dr = cmd.ExecuteReader();
       string a = "";
       //Order Number Generation for Checklist
       while (dr.Read())
       {
           if (dr[0].ToString() == "" || dr[0].ToString() == null)
           {
               a = "1";
           }
           else
           {
               if (dr[0].ToString() == "1")
               {
                   a = Convert.ToString(Convert.ToInt32(dr[0].ToString()) + 9);
               }
               else
               {
                   a = Convert.ToString(Convert.ToInt32(dr[0].ToString()) + 10);
               }
           }
       }
       dr.Close();
       // Generating Checklist Code
       string dr_cmdcode_get = "";
       SqlCommand cmdcode = new SqlCommand("SELECT milestone_code FROM milestones WHERE milestone_name='" + dd1.SelectedValue + "'", amicassaCon);
       SqlDataReader dr_cmdcode = cmdcode.ExecuteReader();
       while (dr_cmdcode.Read())
       {
           dr_cmdcode_get = dr_cmdcode[0].ToString();
           //dr_cmdord_no = dr_cmdcode[1].ToString();
       }
       dr_cmdcode.Close();
       checklistCode = dr_cmdcode_get + '-' + a;

       SqlCommand apdate = new SqlCommand("UPDATE checklists SET milestone_name='" + dd1.SelectedValue + "', checklist_code='" + checklistCode + "' WHERE checklist_name='" + DropDownList2.SelectedValue + "'", amicassaCon);
       SqlDataReader aps = apdate.ExecuteReader();
       aps.Close();


       SqlCommand cmd2 = new SqlCommand("SELECT MAX(CAST(order_no as INT)) FROM activities WHERE checklist_name = '" + dpdchecklist_activity_add.SelectedValue + "'", amicassaCon);
       SqlDataReader dr2 = cmd2.ExecuteReader();
       string b = "";
       //Order Number for Activity
       while (dr2.Read())
       {
           if (dr2[0].ToString() == "" || dr2[0].ToString() == null)
           {
               b = "1";
           }
           else
           {
               if (dr2[0].ToString() == "1")
               {
                   b = Convert.ToString(Convert.ToInt32(dr2[0].ToString()) + 9);
               }
               else
               {
                   b = Convert.ToString(Convert.ToInt32(dr2[0].ToString()) + 10);
               }
           }
       }
       dr2.Close();

       //Generating Activity Code

       string cget = "";
       SqlCommand cmdd = new SqlCommand("SELECT checklist_code FROM checklists WHERE checklist_name='" + DropDownList2.SelectedValue + "'", amicassaCon);
       SqlDataReader drcode = cmdd.ExecuteReader();
       while (drcode.Read())
       {
           cget = drcode[0].ToString();
           //dr_cmdord_no = dr_cmdcode[1].ToString();
       }
       drcode.Close();
       actCode = cget + '-' + b;

       SqlCommand actC = new SqlCommand("UPDATE activities SET milestone_name='" + dd1.SelectedValue + "', activity_code='" + actCode + "' WHERE checklist_name='" + DropDownList2.SelectedValue + "'", amicassaCon);
       SqlDataReader apss = actC.ExecuteReader();
       drcode.Close();



       amicassaCon.Close();

   }
Posted
Updated 1-Oct-14 14:54pm
v2
Comments
George Jonsson 1-Oct-14 21:53pm    
I think you need to describe your table structure for anyone to be able to help you.
Sinisa Hajnal 2-Oct-14 2:42am    
What is the meaning of if ... +9 else +10 parts? Just curious...
DarkDreamer08 2-Oct-14 19:56pm    
if the number is 1, it will added by 9 but if it is not, it will be added by 10
Sinisa Hajnal 3-Oct-14 2:01am    
Yes, yes, I can read the code...but what is the meaning of this increments?
That is, WHY are you adding 9 or 10 depending on the value? :)
DarkDreamer08 3-Oct-14 3:06am    
I'm sorry. It is needed to create the order number which will be added to the last end of the code for the checklist and activity.

1 solution

I have never used this command to execute and update:

C#
SqlDataReader apss = actC.ExecuteReader();


I use an:

ExecuteNonQuery()
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900