Jag kan inte asp eller så och har inte kolla igenom koden speciellt noga. Men är det inte smidigare att ha två tabeller i en databas, istället för två databaser med en tabell i varje?
:)
Hej!
Jag har följande kod:
<%
Dim sSQL, objConn, objRS1, objRS2, iStatus, sNote, sCategory, sName, sArtNr, sUnit, iPrice, iNextId
'Ange status; 0 = "synkroniserad med SPCS", 1 = "Inte synkroniserad mot SPCS"
iStatus = 0
'Notering
sNote = ""
' Öppna databasen
' ***************
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = Application("sConn")
objConn.Open
sSQL = "SELECT tblArticle.articlenumber, tblArticle.articleName, tblPrice.articlePrice, tblPrice.articleCategoryNumber, tblArticle.articleUnit, " &_
"tblCategory.CategoryName, tblCategory.categoryNumber, tblDiscount.articleDiscount, tblSupplier.SupplierName, tblSupplier.SupplierId, " &_
"CASE WHEN articleDiscount is null THEN articlePrice ELSE articlePrice*(1-([articleDiscount]*0.01)) END AS articlePriceWithDiscount " &_
"FROM tblArticle " &_
"INNER JOIN tblPrice ON tblArticle.articlenumber = tblPrice.articleNumber " &_
"INNER JOIN tblSupplier ON tblPrice.articleSupplierId = tblSupplier.SupplierId " &_
"LEFT OUTER JOIN tblDiscount ON tblPrice.articleCategoryNumber = tblDiscount.categoryNumber AND tblPrice.articleSupplierId = tblDiscount.supplierId " &_
"LEFT OUTER JOIN tblCategory ON tblPrice.articleSupplierId = tblCategory.supplierId AND tblPrice.articleCategoryNumber = tblCategory.categoryNumber " &_
"ORDER BY tblArticle.articlenumber"
Set objRS1 = Server.CreateObject("ADODB.Recordset")
objRS1.Open sSQL, objConn, 3, 1
If not objRS1.EOF then
do until objRS1.EOF
sArticleNumber = objRS1("articleNumber")
sArticleName = objRS1("articleName")
sUnit = lCase(objRS1("articleUnit"))
iPrice = replace(cDbl(objRS1("articlePrice")), ",", ".")
'Ta ut de två första tecknena i E-numret
sList = left(sArtNr, 2)
'Hämta kategorinamn mha sList
Set objRS2 = objConn.Execute ("SELECT listName FROM tblList WHERE listNr = '" & sList & "'")
If not objRS2.EOF then
sCategory = objRS2("listName")
End If
objRS2.Close
Set objRS2 = Nothing
[b]'--------------------------------------------------------------------
'Här ska det hämtas info från en annan databas...
Set objRS2 = objConn.Execute ("SELECT nextId FROM tblNextId WHERE table = 'tblArticle'")
If not objRS2.EOF then
iNextId = cLng(objRS2("NextId"))
End If
objRS2.Close
Set objRS2 = Nothing
sSQL = "INSERT INTO tblarticle ([Id], [Group], [Status], [Modified], ArtNr, [Name], [Category], [Unit], [Price], Custom1, Custom2, [Note]) " &_
"VALUES(" & iNextId & ", " & iGroup & ", " & iStatus & ", Now(), '" & sArtNr & "', '" & sName & "', " &_
"'" & sCategory & "', '" & sUnit & "', " & iPrice & ", '" & sCustom1 & "', '" & sCustom2 & "', '" & sNote & "')"
objConn.execute sSQL,,128
sSQL = "UPDATE tblNextId SET nextId = nextId + 1 WHERE Table = 'tblArticle'"
objConn.Execute sSQL,, 128[/b]
objRS1.Movenext
Loop
Else
Response.write "Fel!"
End if
objRS1.Close
Set objRS1 = Nothing
Response.write "Datat har lagrats!"
%>
Koden hämtar data från en tabell i databas 1 och ska hämta och skriva data till tabeller databas 2.
Det som är i fetstil är ifrån databas 2.
Hur gör jag detta?
Jag har följande connectionstring i Global.asa
Sub Application_OnStart
Application("sConn") = "Provider=SQLOLEDB.1;Password=xxxxxxx;Persist Security Info=True;User ID=sa;Initial Catalog=IntranetSydostel;Data Source=.\sqlexpress"
End Sub
Jag använder MS SQL-server
Kanske frågan är i fel forum... flytta i så fall... :)
Mvh
Henrik

