请教大家在VB中调用SQLSERVER中的某个表的代码比如:
我在SQL中建了一个表KS,内容是
001  1号
002 2号
......我在程序中想把这样的文件001 A
002 B
....
经过VB调用SQLSERVER中的表KS变为1号  A
     
2号  B
.....
怎么做?

解决方案 »

  1.   

    有点晕,你是要实现两个表的查询吧
    例如a表 a1,a2;b表b1,b2select a.a2,b.b2 from a,b where a.a1=b.b1就可以了
      

  2.   

    你如果想把表中的数据修改的话用update语句
      

  3.   

    诺原来存储001的字段为A1, 存储1号的字段为B1
    设变量i=001,j=1号
    dim i,j as string
    if i="001" and j="1号" then
       UPdate A1='1号',B1=A from ks where A1='001' and B1='1号'
    else if j="002" and j="2号" then
       UPdate A1='2号',B1=B from ks where A1='002' and B1='2号'
    endif
      

  4.   

    刚才写错,应该为
    dim i,j as string
    if i="001" and j="1号" then
       UPdate KS set A1='1号',B1=A  where A1='001' and B1='1号'
    else if j="002" and j="2号" then
       UPdate KS set A1='2号',B1=B  where A1='002' and B1='2号'
    endif
      

  5.   

    请教大家在VB中调用SQLSERVER中的某个表的代码比如:
    我在SQL中建了一个表KS,内容是
    001  1号
    002 2号
    ......我在程序中想把这样的文本文件Q1.TXT001 A
    002 B
    ....
    经过VB调用SQLSERVER中的表KS变为1号  A
         
    2号  B
    .....文本文件Q2.TXT
    怎么做?
      

  6.   

    1.打开文本文件,按行读取数据
        Dim ofs As FileSystemObject
        Set ofs = New FileSystemObject
        Dim txtstream As TextStream
        Set txtstream = ofso.OpenTextFile(filepath, ForReading)   'filepath就是Q1.txt及其路径      Do Until txtstream.AtEndOfStream
            MsgBox txtstream.ReadLine
         Loop2根据读出数据在数据库中查找,组成新的string array
    dim arrString() as string
    dim i as integer
    i=1
         Do Until txtstream.AtEndOfStream
            redim preserve arrString(1 to i) as string
            sfileString=txtstream.ReadLine
            tempL=left(sfileString,instr(SfileString,1," ")-1)  '按空格分开
            tempR=right(sfileString,len(sfileString)-inst(sfileString,1," "))
            sql="select a.2 from a where a.1='" & tempL& "'"  '默认你的a.1类型varchar 如果是int则作相应转换调整
            rs.open sql,conn,1,1 '相应参数可以再vb中自动显示
            arrString(i)=rs.fields(0) & " " tempR   '默认每个都可以找到对应值,若非则作相应判断
            i=i+1
         Loop
    3.建立Q2.txt并存放
    ofs.CreateTextFile newfilepath,True
    Set txtstream = ofso.OpenTextFile(newfilepath, Forwriting)
    for i=1 to ubound(arrString)
      txtstream.writeling arrString
    next i
    txtstream.Close 各种细节自己添加。希望有所帮助
      

  7.   

    请问sql="select a.2 from a where a.1='" & tempL& "'"
    这句中的a.2和a.1指的是什么?
    我建立的KS表在这段代码中好像没被调用啊!
    多谢!
      

  8.   

    a.2,a.1是字段名字我也不知道你的字段叫什么名字就这样写了a.1 a.2
    001 A
    这样清楚么?