''获取用户输入 strPrompt ="输入州(CA,IN,KS,MD,MI,OR,TN,UT): strState = Trim(InputBox(strPrompt,GetString示例)) ''开放记录集 设置rstAuthors = New ADODB.Recordset strSQLAuthors =" SELECT au_fname,au_lname,address,city FROM Authors" & _ " WHERE state =''" &安培; strState& "''" rstAuthors.Open strSQLAuthors,Cnxn,adOpenStatic,adLockReadOnly, adCmdText 如果不是rstAuthors。 EOF然后 ''使用所有默认值:获取所有行,TAB作为列分隔符, ''CARRIAGE RETURN作为行分隔符,EMPTY-string作为空分隔符 varOutput = rstAuthors.GetString(adClipString) ''打印输出 Debug.Print" State =''" &安培; strState& "''" Debug.Print" Name Address City" &安培; vbCr Debug.Print varOutput 否则 Debug.Print没有找到state ='''的行&安培; strState& "" &安培; vbCr 结束如果 ''清理 rstAuthors.Close Cnxn.Close 设置rstAuthors = Nothing 设置Cnxn = Nothing 退出Sub ErrorHandler: ''清理 如果不是rstAuthors什么都没有那么 如果rstAuthors.State = adStateOpen那么rstAuthors.Close 结束如果 设置rstAuthors = Nothing 如果不是Cnxn则没有那么 如果Cnxn.State = adStateOpen那么Cnxn.Close 结束如果 设置Cnxn = Nothing 如果Err<> 0然后 MsgBox Err.Source& " - >" &安培; Err.Description,错误 结束如果 结束次级 ''EndGetStringVB 昏暗的ID ,fArray str =" SELECT userid FROM RESULTED GROUP BY userid" 设置rsx = cn80.Execute(str) 请不要rsx.EOF ID = rsx(" userid") fArray = fArray& ID&"," rsx.movenext 循环 members = fArray selections =拆分(成员,",") for j = 0 To UBound(选择) ''运行下面的normail例程 下一页 < ;%昏暗的用户ID,数字,cid,sArray str =" SELECT userid,critic_result,critId from RESULTED WHERE userid =''" & 选择(j)& "''" 设置rs = cn80.Execute(str) 请不要rs.EOF numbers = rs(&critic_result") cid = rs(" criticId") userid = rs(" userid") sArray = sArray& cr& cid&" ="&数字&"," rs.movenext 循环 ''Response.write sArray ''开放记录集 str_sql2 =" INSERT INTO SurveyResultsExported(userid," Dim strNames,strValues2 tempArr = Split(sArray,",") for i = 0 to( UBound(tempArr)-1)值= split(tempArr(i)," =") ''创建字段名称列表 strNames = strNames&值(0)&"," ''创建值列表 strValues2 = strValues2&"''"& Values(1)&"'' , 下一步 ''构建SQL STRING然后去吧 str_sql2 = str_sql2& left(strNames,(Len(strNames) )-1))&") VALUES(& pracid&","& left(strValues2,(Len(strValues2)-1))&")" br /> ''cn80.execute(str_sql2) response.write(str_sql2) response.end cn80。关闭设置cn80 =没什么%> 谢谢你的帮助。 webb I have a table with a huge amount of data. At present my data is like so. userid:1588 | 1 | CR1 userid:1588 | 2 | CR2 userid:1588 | 1 | CR3 userid:1588 | 1 | CR4 userid:1588 | 1 | CR5 userid:1588 | 2 | CR6 Intened format below: userid | CR1| CR2| CR3| CR4| CR5| CR6 "Columns" 1588| 1| 2| 1| 1| 1| 2 "Data" I already figured out how to get the data out with some great help. But it works for one record. I have 4342 records how can i loop the routine below to get all id''s fro me. I tried the following but i''m missing something> There is a very convenient function GetSTring on the Recordset objectSample from MSDN This example demonstrates the GetString method. Assume you are debugging a data access problem and want a quick, simple wayof printing the current contents of a small Recordset. ''BeginGetStringVB ''To integrate this code''replace the data source and initial catalog values''in the connection string Public Sub Main()On Error GoTo ErrorHandler '' connection variablesDim Cnxn As ADODB.ConnectionDim rstAuthors As ADODB.RecordsetDim strCnxn As StringDim strSQLAuthors As StringDim varOutput As Variant '' specific variablesDim strPrompt As StringDim strState As String '' open connectionSet Cnxn = New ADODB.ConnectionstrCnxn = "Provider=''sqloledb'';Data Source=''MySqlServer'';" & _"Initial Catalog=''Pubs'';Integrated Security=''SSPI'';"Cnxn.Open strCnxn '' get user inputstrPrompt = "Enter a state (CA, IN, KS, MD, MI, OR, TN, UT): "strState = Trim(InputBox(strPrompt, "GetString Example")) '' open recordsetSet rstAuthors = New ADODB.RecordsetstrSQLAuthors = "SELECT au_fname, au_lname, address, city FROM Authors "& _"WHERE state = ''" & strState & "''"rstAuthors.Open strSQLAuthors, Cnxn, adOpenStatic, adLockReadOnly,adCmdText If Not rstAuthors.EOF Then'' Use all defaults: get all rows, TAB as column delimiter,'' CARRIAGE RETURN as row delimiter, EMPTY-string as null delimitervarOutput = rstAuthors.GetString(adClipString)'' print outputDebug.Print "State = ''" & strState & "''"Debug.Print "Name Address City" & vbCrDebug.Print varOutputElseDebug.Print "No rows found for state = ''" & strState & "''" & vbCrEnd If '' clean uprstAuthors.CloseCnxn.CloseSet rstAuthors = NothingSet Cnxn = NothingExit Sub ErrorHandler:'' clean upIf Not rstAuthors Is Nothing ThenIf rstAuthors.State = adStateOpen Then rstAuthors.CloseEnd IfSet rstAuthors = Nothing If Not Cnxn Is Nothing ThenIf Cnxn.State = adStateOpen Then Cnxn.CloseEnd IfSet Cnxn = Nothing If Err <> 0 ThenMsgBox Err.Source & "-->" & Err.Description, , "Error"End IfEnd Sub''EndGetStringVB dim ID, fArray str ="SELECT userid FROM RESULTED GROUP BY userid" Set rsx = cn80.Execute(str) Do while not rsx.EOF ID = rsx("userid") fArray = fArray & ID &"," rsx.movenext Loop members = fArray selections = Split(members, ",") for j = 0 To UBound(selections) ''run the normail routine here which is below next <% dim userid, numbers, cid, sArray str="SELECT userid, critic_result, criticId from RESULTED WHERE userid=''" & selections(j)& "''" Set rs = cn80.Execute(str) Do while not rs.EOF numbers = rs("critic_result") cid = rs("criticId") userid = rs("userid") sArray = sArray & "cr"&cid &"="& numbers &"," rs.movenext Loop ''Response.write sArray '' open recordset str_sql2 = "INSERT INTO SurveyResultsExported (userid, " Dim strNames,strValues2 tempArr = Split(sArray,",") for i = 0 to (UBound(tempArr)-1) Values = split(tempArr(i),"=") ''CREATE FIELD NAME LIST strNames = strNames & Values(0) & "," ''CREATE VALUE LIST strValues2 = strValues2 & "''" & Values(1) & "'', " next ''BUILD SQL STRING then go for it str_sql2 = str_sql2 & left(strNames, (Len(strNames)-1)) & ") VALUES ("&pracid&", " & left(strValues2, (Len(strValues2)-1)) & ")" ''cn80.execute(str_sql2) response.write(str_sql2) response.end cn80.Close Set cn80 = Nothing %> Thank you for you help. webb 我正在使用SQL Server 2000. Webb " Bob Barrows [MVP]" <再****** @ NOyahoo.SPAMcom>在消息中写道 新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ... I''m using SQL Server 2000. Webb"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in messagenews:%2****************@TK2MSFTNGP09.phx.gbl...什么数据库您使用的是类型和版本吗? - Microsoft MVP - ASP / ASP.NET 请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我不经常检查它。如果您必须离线回复,请删除NO SPAM What database type and version are you using? -- Microsoft MVP - ASP/ASP.NET Please reply to the newsgroup. This email account is my spam trap so I don''t check it very often. If you must reply off-line, then remove the "NO SPAM" 这篇关于数组到另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 04:13