Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

help with C# syntax...

I am a VB.NET developer but I am tring to learn C# I am banging my head againist the wall with some of my syntax and need some help. I will paste the code below.
Also if anyone has any good C# resource websites that would be great.

Code:

how to bind a ddl using a class file that contains my data info:
      private void BindDDL()
            {
            
            DDL Project = new DDL();
            SqlDataReader myRS;
                  myRS = Project.GetSponsers;
                  this.ddlSponsor.DataTextField="DisplayName";
                  this.ddlSponsor.DataValueField="EmployeeID";
                  this.ddlSponsor.DataSource=myRS;
                  this.DataBind();
                  myRS=null;
                  Project = null;
            }

CLASS FILE CODE (this works , i think)
public class DDL
      {
            private string _DatabaseConnectionString;
            public DDL()
            {
                  //
                  // TODO: Add constructor logic here
                  //
                  _DatabaseConnectionString = RSToolBox.configuation.DBConnectionString.GetDBConnection(RSToolBox.configuation.DBConnectionString.DatabaseType.Application);

            }


            public  void GetSponsers()
            {
                  
             SqlHelper.ExecuteReader(_DatabaseConnectionString,CommandType.StoredProcedure, "im_GetEmployees");
            return;
            
            }

button click code

private void btnSave_Click(object sender, System.EventArgs e)
            {
                  ProjectListDB.ProjectList Projects = new ProjectListDB.ProjectList();
                  string strAssignees = "";
                  //int u;
                  for (int u = 0; u <= cblistAssignees.Items.Count - 1; u++)
                  {
                        if (cblistAssignees.Items(u).Selected == true)
                        {
                              strAssignees = strAssignees + cblistAssignees.Items(u).Value + ",";
                        }
                  }
                  if (strAssignees.Length > 0)
                  {
                        strAssignees = Left(strAssignees, strAssignees.Length - 1);
                  }
                  if (strAssignees.Length > 0 & ViewState["AssignDate"] == null)
                  {
                        ViewState["AssignDate"] = System.DateTime.Now.ToShortDateString();
                  }
                  if (ddlStatus.SelectedValue == "Started" & ViewState["StartDate"] == null)
                  {
                        ViewState["StartDate"] = System.DateTime.Now.ToShortDateString();
                  }
                  if (ddlStatus.SelectedValue == "Completed" & ViewState["CompleteDate"] == null)
                  {
                        ViewState["CompleteDate"] = System.DateTime.Now.ToShortDateString();
                  }
                  int NewProjectID;
                  NewProjectID = Projects.SaveSystems_ProjectList(ViewState["ProjectID"], tbDescription.Text, ddlSponsor.SelectedValue, ddlProjectedHrs.SelectedValue, ddlPriority.SelectedValue, CalDeadLine.Text, ViewState["RequestDate"], ViewState["AssignDate"], ViewState["StartDate"], ViewState["CompleteDate"], ddlStatus.SelectedValue, tbNotes.Text, strAssignees);
                  tbDescription.Text = "";
                  ddlProjectedHrs.SelectedIndex = 0;
                  ddlSponsor.SelectedIndex = 0;
                  tbNotes.Text = "";
                  if (!ViewState["ProjectID"]>0)
                  {
                        RegisterClientScriptBlock("message", "<script>alert('Project Request Added!');location.href='Projects.aspx'</script>");
                  }
                  else
                  {
                        if (ViewState["Page"] == 1)
                        {
                              RegisterClientScriptBlock("message", "<script>location.href='Projects.aspx'</script>");
                        }
                        else
                        {
                              if (ViewState["Rpt"] == "a")
                              {
                                    RegisterClientScriptBlock("message", "<script>location.href='http://uspghrpt01/ReportServer?%2fSystems+And+Technology%2fProjectList+Reports%2fProjectListAssigneeListRpt&rs:Command=Render'</script>");
                              }
                              else
                              {
                                    RegisterClientScriptBlock("message", "<script>location.href='http://uspghrpt01/Reports/Pages/Report.aspx?ItemPath=%2fSystems+And+Technology%2fProjectList+Reports%2fProjectListTBAReport'</script>");
                              }
                        }
                  }

            }
0
jcook32
Asked:
jcook32
  • 4
  • 3
  • 2
  • +1
1 Solution
 
mistaeverlyCommented:
You may need to be more specific about what you're asking.  I'd like to help but don't know where to start.
0
 
jcook32Author Commented:
Thanks
this line
myRS = Project.GetSponsers;myRS = Project.GetSponsers;
give me this error:
Method DDL.GetSponsers()' referenced without parentheses

if i add the parens get this errror
CAnnot implicitly covert type void to system.data.sqlclient.sqldatareader


in this line
if (cblistAssignees.Items(u).Selected == true)

System.web.ui.webcontrols.listcontrol.items ' denotes a property where a method was expected

in this line
if (ViewState["Page"] == 1)

Operator == cannot be applied to operands of type object and int

those are the errors and lines that are causing them.



0
 
Carl TawnSystems and Integration DeveloperCommented:

    myRS = Project.GetSponsers();

This is causing a problem because the method doesn't return anything. You possibly need the change the method to:

          public  SqlDataReader GetSponsers()
          {
               return SqlHelper.ExecuteReader(_DatabaseConnectionString,CommandType.StoredProcedure, "im_GetEmployees");        
          }

Syntax correction on this line:

    if (cblistAssignees.Items(u).Selected == true)

Should be:

    if (cblistAssignees.Items[u].Selected == true)


And this line:

    if (ViewState["Page"] == 1)

Should probably be:

    if ( ((int)ViewState["Page"]) == 1)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jcook32Author Commented:
Thank you.
one more if you can

if (!((int)ViewState["ProjectID"])>0)

i had the len function around it but that is not valid

operand cannot be applied to operand of type int
0
 
Carl TawnSystems and Integration DeveloperCommented:
What data type should ProjectID be ?

If its supposed to be int then "len" is not valid. If its supposed to be string then you need to change it to:

    if (!((string)ViewState["ProjectID"]).Length > 0)
0
 
jcook32Author Commented:
should be an int
0
 
Carl TawnSystems and Integration DeveloperCommented:
In that case the "len" function is not valid. Length of an integer value has no meaning.
0
 
gbzhhuCommented:
I guess you are trying to say if the ProjectID is less than or equal to 0 (same as not greater than or equal to 0) try this

if ((int)ViewState["ProjectID"] <= 0)
0
 
jcook32Author Commented:
Thank you thatn worked great.

you got the points
0
 
gbzhhuCommented:
Since I am not sure what operator condition you are testing here is an overview

Operators

==        equals
!=         not equal
<          less than
>          greater than
<=        less than or equal to
>=        greater than or equal to
!           Negate (not)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now