How to programmatically set values in .NET 2.0

Last post 02-13-2007 11:54 AM by axeman420. 8 replies.

Sort Posts:

  • How to programmatically set values in .NET 2.0

    02-09-2007, 3:47 PM
    • Member
      46 point Member
    • axeman420
    • Member since 11-01-2004, 11:27 AM
    • Posts 51

    Hello all,

    I have set up a page with a gridview and formview to show the details. All this information is pulled from SQL 2005 tables. What I am wanting to do is on Formview_ModeChanged and Formview.CurrentMode = EditMode then I want it to pull updated values from an Oracle table. Basically the user selects a record from the gridview and then sees the details in the formview section. Once they click on the Edit button on the Formview some of the data is bounced off of the Oracle database in order to pull the latest values (for example updating the latest employee information from a central database into my database). Then the user can make any changes to the record and ALL updates are sent to the SQL 2005 database. I had some script that did this in ASP.NET 1.1 but in 2.0 every data source is linked to some databound control. Is there any way to do this like in ASP.NET 1.1 or even an easier way?

    Thanks in advance,

  • Re: How to programmatically set values in .NET 2.0

    02-11-2007, 4:38 PM
    • Member
      46 point Member
    • axeman420
    • Member since 11-01-2004, 11:27 AM
    • Posts 51

    Wow. Nobody has any ideas or can provide any help on this?

     In ASP.NET 1.1 I used a datareader to pull all the values. In .NET 2.0 there isn't a direct way to do this. That I know of anyways. Any help would be greatly appreciated.

    Thanks in advance,

    Axe

  • Re: How to programmatically set values in .NET 2.0

    02-12-2007, 4:13 AM
    • Star
      12,348 point Star
    • Mr^B
    • Member since 02-12-2006, 11:38 AM
    • Posts 2,189

    Hi,

    Can you post an example of the code that you are using in 1.1?  It's too early in the morning for me to conceptualize what the problem is, but there's no reason why you can't dynamically bind data from a datareader into a gridview/form whatever in 2.0.
     

    MCSD.Net
  • Re: How to programmatically set values in .NET 2.0

    02-12-2007, 8:22 AM
    • Member
      46 point Member
    • axeman420
    • Member since 11-01-2004, 11:27 AM
    • Posts 51

    Well here's the problem. I already have a gridview/formview set up with their sql datasources. My only problem is that once the user clicks on the edit button I want it to pull data from the Oracle table. All I'm doing is refreshing the employee information with data from our central database. Here's the code on how I did it in 1.1:

    Sub EditForm(sender As Object, e As System.EventArgs)
     cmbCallStatus.Enabled = "True"
     cmbCallerType.Enabled = "True"
     txtCallerEmployeeID.Enabled = "True"
     txtCallerPhone1.Enabled = "True"
     txtCallerPhone2.Enabled = "True"
     cmbMajBusFunctionArea.Enabled = "True"
     cmbCompetitiveHireInfo.Enabled = "True"
     txtHROMNotes.Enabled = "True"
     btnEdit.Enabled = "False"
     btnUpdate.Enabled = "True"
     
     'Reload EV2 Employee Information
     Dim strEE As String
     Dim HireDate As Date
     strEE = lblEmployeeID.Text
     
     Dim oOracleConn As OracleConnection = New OracleConnection()
     Dim dataReader As OracleClient.OracleDataReader
     oOracleConn.ConnectionString = "Data Source=test;User Id=test;Password=test;Integrated Security=no;"
     Dim myInsertQuery As String = "SELECT * FROM myOracleView WHERE EMPLOYEE_NUMBER='" & strEE & "'"
     Dim myOracleCommand As New OracleCommand(myInsertQuery)
     myOracleCommand.Connection = oOracleConn
     oOracleConn.Open()
     dataReader = myOracleCommand.ExecuteReader()
     If dataReader.Read() = True Then
      lblEmployeeLastName.text=dataReader("EMPLOYEE_LAST_NAME").ToString()
      lblEmployeeFirstName.text=dataReader("EMPLOYEE_FIRST_NAME").ToString()
      lblMgrEmployeeID.text=dataReader("SUPERVISOR_ID").ToString()
      lblMgrLastName.text=dataReader("MANAGER_LAST_NAME").ToString()
      lblMgrFirstName.text=dataReader("MANAGER_FIRST_NAME").ToString()
      lblOrgCode.text=dataReader("DEPARTMENT").ToString()
      lblOrgName.text=dataReader("DEPARTMENT_DESCRIPTION").ToString()
      lblWorkLocationCity.Text=dataReader("WORK_LOCATION_CITY").ToString()
      lblWorkLocationState.Text=dataReader("WORK_LOCATION_STATE").ToString()
      lblAge.Text=dataReader("AGE")
      lblDOB.Text=dataReader("BIRTHDATE")
      lblEmployeeStatusCode.Text=dataReader("XE_STATUS_CD").ToString()
      lblEmployeeStatusDesc.Text=dataReader("STATUS_DESCR").ToString()
      lblEmployeeStatusEffDate.Text=FormatDateTime(dataReader("XE_ST_ENTRY_DT"), DateFormat.ShortDate)
      lblJobCode.Text=dataReader("JOBCODE")
      lblJobTitle.text=dataReader("JOB_DESCRIPTION").ToString()
      HireDate=dataReader("ORIGINAL_HIRE_DT")
      lblHireDate.text=HireDate.ToString("d")
      lblYrsOfService.Text=dataReader("SERVICE_YEARS")
           
      Select Case dataReader("ETHNIC_GRP_CODE").ToString()
       Case "1"
        lblEEO.text=("1 - White (Not of Hispanic Origin)")
       Case "2"
        lblEEO.text=("2 - Black (Not of Hispanic Origin)")
       Case "3"
        lblEEO.text=("3 - Hispanic")
       Case "4"
        lblEEO.text=("4 - Asian or Pacific Islander")
       Case "5"
        lblEEO.text=("5 - American Indian / Alaskan Native")
       Case Else
      End Select
      
      Select Case dataReader("SEX_CODE").ToString()
       Case "F"
        lblGender.text=("Female")
       Case "M"
        lblGender.text=("Male")
       Case Else
      End Select
      
      Select Case dataReader("EDUCATION_CD").ToString()
       Case "1"
        lblEducation.text=("Associates")
       Case "2"
        lblEducation.text=("Bachelors")
       Case "3"
        lblEducation.text=("Masters")
       Case "4"
        lblEducation.text=("Doctorate")
       Case "A"
        lblEducation.text=("1-2 Years")
       Case "B"
        lblEducation.text=("3-4 Years")
       Case "C"
        lblEducation.text=("Post Bach")
       Case "D"
        lblEducation.text=("Post Mast")
       Case "E"
        lblEducation.text=("Post Doct")
       Case Else
      End Select
      
      Select Case dataReader("REFERRAL_SOURCE").ToString()
        Case "AD"
         lblReferralSource.text=("Advertisement")
        Case "AG"
         lblReferralSource.text=("N/A")
        Case "AQ"
         lblReferralSource.text=("Acquisition")
        Case "CA"
         lblReferralSource.text=("Career Center")
        Case "CC"
         lblReferralSource.text=("Contract Worker Conversion")
        Case "CO"
         lblReferralSource.text=("College Recruiting")
        Case "CR"
         lblReferralSource.text=("Corporate/Direct Recruiting")
        Case "EA"
         lblReferralSource.text=("Employment Agency")
        Case "EE"
         lblReferralSource.text=("Employee Referral")
        Case "FE"
         lblReferralSource.text=("Former Employee")
        Case "IN"
         lblReferralSource.text=("Internet Posting")
        Case "JF"
         lblReferralSource.text=("Job Fair")
        Case "JP"
         lblReferralSource.text=("Job Posting")
        Case "OT"
         lblReferralSource.text=("Other Source")
        Case "US"
         lblReferralSource.text=("Unsolicited")
        Case "XR"
         lblReferralSource.text=("Executive Referral")
        Case "XS"
         lblReferralSource.text=("Executive Search")
        Case Else
       End Select
      dataReader.Close()
     End If
     oOracleConn.Close()
     
     Page.Validate
    End Sub

  • Re: How to programmatically set values in .NET 2.0

    02-13-2007, 6:54 AM
    Answer
    • Star
      12,348 point Star
    • Mr^B
    • Member since 02-12-2006, 11:38 AM
    • Posts 2,189
    There's no reason why that code won't work in .Net 2.0 - all you're doing is opening up a DataReader and populating text labels with its contents.
    MCSD.Net
  • Re: How to programmatically set values in .NET 2.0

    02-13-2007, 8:34 AM
    • Member
      46 point Member
    • axeman420
    • Member since 11-01-2004, 11:27 AM
    • Posts 51

    Is there not a more efficient way of doing this in 2.0? Just wondering. I don't want to stick to old code if it can be done a better way.

  • Re: How to programmatically set values in .NET 2.0

    02-13-2007, 10:07 AM
    Answer
    • Star
      12,348 point Star
    • Mr^B
    • Member since 02-12-2006, 11:38 AM
    • Posts 2,189
    Not as far as I know, no.  If you have a form that's not a built-in server object (like a gridview, etc) then you have to bind everything in that way.
    MCSD.Net
  • Re: How to programmatically set values in .NET 2.0

    02-13-2007, 10:12 AM
    • Member
      46 point Member
    • axeman420
    • Member since 11-01-2004, 11:27 AM
    • Posts 51

    Now here's my other problem. I'm using the code above to populate the fields. The only difference is that now these fields are inside a tabcontainer, inside a tab, inside a formview control. When I try to use the formview.findcontrol method it simply cannot find the control for some reason. I've ensure that I am doing this on the itemdatabound event so I know that the fields I'm searching for are the right ones.

    Any ideas?

    Axe

  • Re: How to programmatically set values in .NET 2.0

    02-13-2007, 11:54 AM
    • Member
      46 point Member
    • axeman420
    • Member since 11-01-2004, 11:27 AM
    • Posts 51

    Nevermind. I stepped/debug through the code and found out that my NullReferenceException was coming from my connection string not that it could not find the controls.

    Thank you for your help!

    Axe

Page 1 of 1 (9 items)