Solved

Insert Openquery to Oracle server from asp.net

Posted on 2010-08-31
5
613 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now