Solved

Insert Openquery to Oracle server from asp.net

Posted on 2010-08-31
5
627 Views
Last Modified: 2012-06-27
Before the following sql statment went to a sql server so it was no problem but now i need to send it over a linked server to an oracle server, how can i change this to use openquery insert.

sql = "Insert tblACNRequest (strAcn, intRecruitId, intRecruiterRecordid, strUic, strPara, strLine, strGrade, strDmos, strNotes, dtExpire, dtTimeStamp) " _
            & "Values ('" & lblAcnNum.Text & "', " & Session("id") & ", " & lblhidden.Text & ", '" & lblUIC.Text & "', '" & lblPara.Text & "', " _
            & "'" & lblLine.Text & "', '" & lblGrade.Text & "', '" & lblDmos.Text & "', '" & txtNotes.Text & "', '" & lblACNDate.Text & "', '" & Date.Now() & "')"
Oracle server statement

sql = "INSERT OPENQUERY(SIDPERS, 'Select ??????')
Values ('" & lblAcnNum.Text & "')

Open in new window

0
Comment
Question by:kdeutsch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 350 total points
ID: 33569836
Assuming you run it from SQL against ORACLE Lin ked Server you should run something like the statement below but where the VALUES must be replaced with the actual value - you can use variables for each of the values in the list then build a string and in the end exec(print first for debuging) that string.

INSERT INTO OPENQUERY(SIDPERS,
'SELECT strAcn, intRecruitId, intRecruiterRecordid, strUic, strPara, strLine, strGrade, strDmos, strNotes, dtExpire, dtTimeStamp FROM tblACNRequest')
values (lblAcnNum, Session(id), lblhidden, lblUIC, lblPara, lblLine, lblGrade, lblDmos, txtNotes, lblACNDate, Date);
0
 

Author Comment

by:kdeutsch
ID: 33588373
lcohan:

Well, I tried it but for some reason my values are not being picked up by the insert string.

Here is the code I am useing on myVb page.
 Private Sub lnkSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSubmit.Click
        Dim Acn As String = 11 - 222 - 1
        Dim SSN As String = "333333333"
        Dim ACNStat As Integer = 4
        Dim TimeStamp As String = Date.Now()
        Dim logon As String = Split(Current.User.Identity.Name, "\")(1)
        Dim DtExpire As String = lblACNDate.Text
        Dim RecruitId As Integer = Session("id")
        Dim RecruiterID As Integer = lblhidden.Text
        Dim Uic As String = lblUIC.Text
        Dim Para As String = lblPara.Text
        Dim Line As String = lblLine.Text
        Dim Grade As String = lblGrade.Text
        Dim Dmos As String = lblDmos.Text
        Dim Notes As String = Replace(txtNotes.Text, "'", "''")

        Acn = "11-222-1"


        'Generate new SID #
        'GenerateNewId()
        sql = "Select strSSN from tblRecruit where intRecruitId = " & Session("id")
        myDataTable = New DataTable
        myDataTable = getData(sql)

        SSN = myDataTable.Rows(0)(0)

        'Save all the information and Create ACN number
        sql = "INSERT INTO OPENQUERY(SIDPERS, 'SELECT ACN, SSN_SM, ACN_STATUS, DT_ISSUED, ISSUED_BY, DT_EXPIRE, RSID, NCOID, UIC, PARA, LINE, REMARKS, GRADE, MOS FROM ACN.ACN_CNTL_NBR_TBL') " _
                & "values (ACN, SSN, ACNSTat, TimeStamp, logon, DtExpire, RecruitId, RecruiterID, Uic, Para, Line, Grade, Notes, Grade, Dmos);"

        Response.Write(sql)
        Response.End()
        insertUpdateDelete(sql)
0
 

Author Comment

by:kdeutsch
ID: 33588432
Never mind being retarded today forgot to add the " & Value & "
0
 

Author Comment

by:kdeutsch
ID: 33620352
Ok, finally got permissions to this table and it worked fine, Thanks
0
 

Author Closing Comment

by:kdeutsch
ID: 33620362
Thanks
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question