webForumDet fria alternativet

Hur många nya och uppdaterade poster

ASP

2 svar · 314 visningar · startad av devotion

Medlem sedan jan. 20013 582 inlägg
Frågan#1

Hej!

Hur får jag fram informationen om hur många poster som uppdaterades respektive lades till?

Har följande kod:

					'Uppdatera tblArticle om artikeln redan finns
					sSQL = "UPDATE tblArticle SET articleNumber = '" & sEnumber & "', articleName = '" & sArticleName & "', articleUnit = '" & sUnit & "' WHERE articleNumber = '" & sEnumber & "'"
					objConn.Execute sSQL, lngRA, 128
				
					if lngRa = 0 then
						'Lägga till artikeln i tblArticle om den inte finns
						sSQL = "INSERT INTO tblArticle (articleNumber, articleName, articleUnit) VALUES ('" & sEnumber & "', '" & sArticleName & "', '" & sUnit & "')"		
						objConn.Execute sSQL,,128
					End if
					
					'Uppdatera tblPrice om artikeln redan finns
					sSQL = 	"UPDATE tblPrice SET articleNumber = '" & sEnumber & "', articleSupplierId = " & iSupplierId & ", articlePrice = " & iPrice & ", " &_ 
							"articleCategoryNumber = '" & sCategory & "' WHERE articleNumber = '" & sEnumber & "' AND articleSupplierId = " & iSupplierId
							
					objConn.Execute sSQL, lngRA, 128
				
					if lngRA = 0 then
						'Lägga till artikeln i tblPrice om den inte finns
						sSQL =  "INSERT INTO tblPrice (articleNumber, articleSupplierId, articlePrice, articleCategoryNumber) " &_
								"VALUES ('" & sEnumber & "', " & iSupplierId & ", " & iPrice & ", '" & sCategory & "')"
						objConn.Execute sSQL,, 128
					End If

Mvh
Henrik

Medlem sedan juni 200032 967 inlägg
#2

Variabeln lngRA innehåller antalet poster som uppdaterades när du har kört dina SQL-frågor (när du har med den i execute-anropet).

Du får skapa ett par variabler i asp som du räknar med, typ:

[b]lUpdates = 0[/b]
[b]lInserts = 0[/b]

.......

'Uppdatera tblArticle om artikeln redan finns
sSQL = "UPDATE tblArticle SET articleNumber = '" & sEnumber & "', articleName = '" & sArticleName & "', articleUnit = '" & sUnit & "' WHERE articleNumber = '" & sEnumber & "'"
objConn.Execute sSQL, lngRA, 128

[b]lUpdates = lUpdates + lngRA[/b]

if lngRa = 0 then
'Lägga till artikeln i tblArticle om den inte finns
	sSQL = "INSERT INTO tblArticle (articleNumber, articleName, articleUnit) VALUES ('" & sEnumber & "', '" & sArticleName & "', '" & sUnit & "')"		
	objConn.Execute sSQL,,128
	[b]lInserts = lInserts + 1[/b]
End if

'Uppdatera tblPrice om artikeln redan finns
sSQL = 	"UPDATE tblPrice SET articleNumber = '" & sEnumber & "', articleSupplierId = " & iSupplierId & ", articlePrice = " & iPrice & ", " &_ 
		"articleCategoryNumber = '" & sCategory & "' WHERE articleNumber = '" & sEnumber & "' AND articleSupplierId = " & iSupplierId
		
objConn.Execute sSQL, lngRA, 128
[b]lUpdates = lUpdates + lngRA[/b]

if lngRA = 0 then
	'Lägga till artikeln i tblPrice om den inte finns
	sSQL =  "INSERT INTO tblPrice (articleNumber, articleSupplierId, articlePrice, articleCategoryNumber) " &_
			"VALUES ('" & sEnumber & "', " & iSupplierId & ", " & iPrice & ", '" & sCategory & "')"
	objConn.Execute sSQL,, 128
	[b]lInserts = lInserts + 1[/b]
End If

Jag passar också på att flytta tråden från SQL.

mvh

Medlem sedan jan. 20013 582 inlägg
#3

Tackar!
Funkar finfint! :D

Bra att du flyttade tråden.... Blev lite fel där...

Mvh
Henrik

288 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
128 ms — deklarationer (db)
0 ms — hämta statistik (cache)
157 ms — hämta tråd, inlägg och bilagor (db)
119 ms — ändringar (db)