Solved

Insert Openquery to Oracle server from asp.net

Posted on 2010-08-31
5
625 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
  • 4
5 Comments
 
LVL 39

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

808 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