में फ़ंक्शन से रिटर्न रिकॉर्डसेट क्लासिक एएसपी में किसी फ़ंक्शन से मैं एक पठनीय रिकॉर्डसेट कैसे लौटा सकता हूं इस पर एक नुकसान है।क्लासिक एएसपी
यह है कि मैं क्या के साथ आया है, लेकिन यह काम नहीं कर रहा:
Response.Clear
Response.CharSet = "utf-8"
Response.ContentType = "text/plain"
Dim Count
Set Count = Test
Response.Write Count.Fields(0).Value
Function Test
Dim Query, Connection, Command, Recordset
Query = " blah blah blah "
Set Connection = Server.CreateObject("ADODB.Connection")
Set Command = Server.CreateObject("ADODB.Command")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Connection.ConnectionString = "blah blah blah"
Connection.Open
Set Command.ActiveConnection = Connection
Command.CommandText = Query
Set Recordset = Command.Execute
Set Test = Recordset
Recordset.Close
Connection.Close
Set Recordset = Nothing
Set Command = Nothing
Set Connection = Nothing
End Function
Response.Write Count.Fields(0).Value
लाइन Item cannot be found in the collection corresponding to the requested name or ordinal.
त्रुटि अर्जित करता है।
इसे Response.Write Count.Status
के साथ बदलकर मुझे Operation is not allowed when the object is closed.
त्रुटि मिलती है।
Count.Open
जोड़ना The connection cannot be used to perform this operation. It is either closed or invalid in this context.
त्रुटि देता है।
संपादित मार्क बी के जवाब के बाद:
मैं पहले से ही कट recordsets को देखा है, लेकिन मैं कैसे मेरे उदाहरण में उन्हें इस्तेमाल करना नहीं आता: हर ट्यूटोरियल सीधे Recordset.Open
साथ recordset में क्वेरी खिलाती है, लेकिन मैं मैं parametrized प्रश्नों का उपयोग कर रहा हूं, और यहां तक कि कई तरीकों की कोशिश कर रहा हूं, जिस तरह से मुझे ADODB.Command
रास्ते में एक ही परिणाम प्राप्त नहीं हो सका।
मुझे क्या करना चाहिए?
अग्रिम धन्यवाद।
यहाँ समाधान एडुआर्डो Molteni के उत्तर के आधार पर दिया गया है:
समारोह जो डेटाबेस के साथ सूचना का आदान प्रदान:
Function Test
Dim Connection, Command, Recordset
Set Connection = Server.CreateObject("ADODB.Connection")
Set Command = Server.CreateObject("ADODB.Command")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Connection.ConnectionString = "blah blah blah"
Connection.Open
Command.ActiveConnection = Connection
Command.CommandText = "blah blah blah"
Recordset.CursorLocation = adUseClient
Recordset.Open Command, , adOpenForwardOnly, adLockReadOnly
Set Recordset.ActiveConnection = Nothing
Set Test = Recordset
Connection.Close
Set Recordset = Nothing
Set Command = Nothing
Set Connection = Nothing
End Function
कोड जो फ़ंक्शन को कॉल:
Response.Clear
Response.CharSet = "utf-8"
Response.ContentType = "text/plain"
Dim Recordset
Set Recordset = Test
Response.Write Recordset.Fields(0).Value
Recordset.Close
Set Recordset = Nothing
आपका कोड के अंतिम हिस्सा 'याद आ रही है Response.CodePage = 65001' देता है। – AnthonyWJones