Solved

Insert Openquery to Oracle server from asp.net

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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.

863 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

21 Experts available now in Live!

Get 1:1 Help Now