How to code an add button and update button, in Visual Studio, that adds or updates a record in Oracle...

Update Statement , Visual Basic , Visual Studio , Oracle , Add Statement Chicago, United States
  • 10 years ago

    After a add button is clicked, I want to be able to add a record into an Oracle database with the info added into textboxes. Similarly I want an update button to update a record in an Oracle database with info added into textboxes. Here's what I've got. Visual Studio is having trouble with this.

    Private Sub btnAddClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim XE As String = "Data Source=(DESCRIPTION=(ADDRESSLIST=" _ + "(ADDRESS=(PROTOCOL=TCP)(HOST=" + txtHost.Text + ")(PORT=1521)))" _ + "(CONNECTDATA=(SERVER=DEDICATED)(SERVICENAME=XE) ));" _ + "User Id=system;Password=**;" Dim conn As New OracleConnection(XE)

    conn.Open()

    Dim cmd As New OracleCommand

    cmd.Connection = conn cmd.CommandText = "Insert EmployeeID, FirstName, LastName, EMail, PhoneNumber, HireDate, JobID, Salary, CommissionPct, ManagerID, DepartmentID INTO hr.Employees WHERE EmployeeID = " + txtEmployeeID.Text cmd.CommandType = CommandType.Text

    cmd.ExecuteNonQuery()

    cmd.Dispose() conn.Dispose() End Sub

    Private Sub btnUpdateClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click Dim XE As String = "Data Source=(DESCRIPTION=(ADDRESSLIST=" _ + "(ADDRESS=(PROTOCOL=TCP)(HOST=" + txtHost.Text + ")(PORT=1521)))" _ + "(CONNECTDATA=(SERVER=DEDICATED)(SERVICENAME=XE) ));" _ + "User Id=system;Password=**;" Dim conn As New OracleConnection(XE)

    conn.Open()

    Dim cmd As New OracleCommand

    cmd.Connection = conn cmd.CommandText = "Update EmployeeID, FirstName, LastName, EMail, PhoneNumber, HireDate, JobID, Salary, CommissionPct, ManagerID, DepartmentID FROM hr.Employees WHERE EmployeeID = " + txtEmployeeID.Text cmd.CommandType = CommandType.Text

    cmd.ExecuteNonQuery()

    cmd.Dispose() conn.Dispose() End Sub

  • 10 years ago

    private void insertdata() { try { string scategoryname, susername, spassword, scountry, semail, scomName, sConPerson, Sdesig, sAreaOf, sCity, sTerm; string sphone_std, sphonelandline, sphonemobile, sNri, sProvince, scompurl;

            scomName = txtCompanyName.Text;
            sConPerson = txtContactPerson.Text;
            Sdesig = txtDesignation.Text;
            string companylogo = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf("\\") + 1);
            scompurl = txtCompanyUrl.Text;
            sAreaOf = txtCitiesofOperation.Text;
            string annualturn = ddlYearOfoperation.SelectedItem.Text;
            string propertiessold = ddlPropertiesSoldLastYear.SelectedItem.Text;
    
            string companyprofile = txtBuilderProfile.Text;
    
            string str;
    
            str = "insert into myproperty_userinfo(categoryname,user_name,Password,country,Province,City,Phone_std,phone_Landline,Phone_mobile,email,companyname,contactperson,designation,companyLogo,companyurl,Areaofbusiness,nationalPresence,Internationalnetwork,CompanyProfile,TermCondition)values" +
            "('" + scategoryname + "','" + susername + "','" + spassword + "','" + scountry + "','" + sProvince + "','" + sCity + "'," + sphone_std + "," + sphonelandline + "," + sphonemobile + "," +
            "'" + semail + "','" + scomName + "','" + sConPerson + "','" + Sdesig + "','" + companylogo + "','" + scompurl + "','" + sAreaOf + "','" + annualturn + "','" + propertiessold + "','" + companyprofile + "','" + sTerm + "')";
            ImageLoadImgthum(this.FileUpload1);
    
            con.ExecuteData(str);
            Response.Redirect("RegIndividualConfirmation.aspx");
    
    
    
        }
        catch (Exception ex)
        {
            this.Labe1.Text = ex.Message.ToString();
    
        }
    
    }
    
  • 10 years ago

    Thanks for the reply... I figured the insert part out....I just can't get the update button working...

  • 10 years ago

    I Gve u update code u can chage it as u want. it's vb.net code. nd here i also used in logic class. if u don't able to chage it then mail me on jitender.gupta007@gmail.com

           Sub UpdateProfile()
            Dim intSMSMessage As Integer
            Dim strUserType As String
            Dim objBusinessLogic As New mylogic.BusinessLogic.BusinessLogic
    
            If (Me.RD_Individual.Checked = True) Then
                strUserType = "I"
            End If
            If (Me.RD_Broker.Checked = True) Then
                strUserType = "A"
            End If
            If (Me.RD_Builder.Checked = True) Then
                strUserType = "B"
            End If
    
            If (Me.CHK_SMSMobile.Checked = True) Then
                intSMSMessage = 1
            Else
                intSMSMessage = 0
            End If
    

    objBusinessLogic.UpdateProfile(strUserType, Me.TRFirstName.Text, Me.TNLastName.Text, Me.EREmail.Text, Me.TRCompanyName.Text, Me.TRCompanyAddress.Text, Me.DDLCountry.SelectedItem.Text, Me.DDLState.SelectedItem.Value, Me.DDLCity.SelectedItem.Value, Me.TNWebsiteURL.Text, Me.TRMobile.Text, intSMSMessage, Me.TNLandline.Text, Me.TNSTDCode.Text, Request.QueryString("ADDOPER")) ClearField() Me.LBL_MESSAGE.Text = "Your Data has Been Updated Succesfully"

        End Sub
    
  • 10 years ago

    After a modify button is clicked, I want to be able to modify a record into an sql serveur2000

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are 10 types of people in the world, those who can read binary, and those who can't.”