佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 2264|回复: 27

Ms SQL SERVER 的問題.

[复制链接]
发表于 20-12-2004 06:09 PM | 显示全部楼层 |阅读模式
我有個問題想要大家幫幫忙, 那就是有關MS SQL Server的問題.

p/s:我想請問那裡可以找到有關importing & Exporting Data的資料.
回复

使用道具 举报


ADVERTISEMENT

发表于 20-12-2004 07:21 PM | 显示全部楼层
你是想说用DTS还是手动?
回复

使用道具 举报

 楼主| 发表于 20-12-2004 07:35 PM | 显示全部楼层
DTS是什麼來的..
我要的是手動的...
其實我是知道怎樣importing 7 exporting data in EM,可是我現在要presentation所以我想參考人家怎樣做.
回复

使用道具 举报

发表于 20-12-2004 08:17 PM | 显示全部楼层
直接right click,就会看到import data的功能了...按它的wizard一步一步做就行了
回复

使用道具 举报

发表于 20-12-2004 09:03 PM | 显示全部楼层
以下有个问题L:
请问有没有人知道如何用 VB 6.0 的coding 来 import text file 去 MS SQL 2000,我的 text file 类似如下 :
Text file name = text1.txt
Name              Age              Position
AAAAAAA     55                 Sales Manager
bbb                 22                  Sales man
....     ....      ..........
...     ..........
.....
.....

这个 text file的fields 不被";", "tab", ","或......来分别,所以当我要import时,我必需算这个field里maximum可以到多少character,以下是我从网上找到的coding,可是不能用(可能是我自己也不很明白吧 !) ,有bug(根本link不到MS SQL 2000 server),再说我也是初学MS SQL 2000,so我觉得我link MS SQL 2000 Server 的那排coding 有很大问题! 有谁有这方面的经验吗?? 请帮帮忙!!

Coding :
Function ImportTextFile2()

Dim LineData As String
Dim NameAs String
Dim Age As String
Dim Pos As String

Open "D:\Systems\Packing\txt file\text1.txt" For Input As #1

DoCmd.OpenTable "EmpProfile", acNormal, acEdit

Do While Not EOF(1)
Line Input #1, LineData

Name= Trim(Mid(LineData, 2, 30))
Age= Trim(Mid(LineData, 33, 3))
Pos = Trim(Mid(LineData, 37, 20))

Loop
' Close the data file.
Close #1

End Function

我的疑问:
“DoCmd.OpenTable "EmpProfile", acNormal, acEdit” , 这行code拿来call MS Access 就行啦, call MS SQL 2000 Server 的code又该怎么写,在 VB 6.0 里又该select 哪些reference 和 component 呢?
回复

使用道具 举报

 楼主| 发表于 21-12-2004 07:50 AM | 显示全部楼层
astral 于 20-12-2004 08:17 PM  说 :
直接right click,就会看到import data的功能了...按它的wizard一步一步做就行了



我知道要怎樣Import & Export, 我現在要的是他的detail link,最好是有image step by step importing & Exporting data.
回复

使用道具 举报

Follow Us
发表于 21-12-2004 11:16 AM | 显示全部楼层
海星1988 于 20-12-2004 09:03 PM  说 :
以下有个问题L:
请问有没有人知道如何用 VB 6.0 的coding 来 import text file 去 MS SQL 2000,我的 text file 类似如下 :
Text file name = text1.txt
Name              Age              Position
AAA ...


不好意思,请问你的DoCmd是什么object?
回复

使用道具 举报

发表于 21-12-2004 01:08 PM | 显示全部楼层
说真的,我也不大清楚, 不过你一定要在reference里选"Microsift Access 11.0 object library", 它才能被启用!
ei.., 我想是open MS Access Database的一道门吧!
回复

使用道具 举报


ADVERTISEMENT

发表于 22-12-2004 09:16 AM | 显示全部楼层
DRAGONISM 于 21-12-2004 11:16 AM  说 :


不好意思,请问你的DoCmd是什么object?


DoCmd 是 access 里的一个 method, 专门执行 access 内建的 command.
回复

使用道具 举报

发表于 22-12-2004 09:24 AM | 显示全部楼层
海星1988 于 20-12-2004 09:03 PM  说 :
以下有个问题L:
请问有没有人知道如何用 VB 6.0 的coding 来 import text file 去 MS SQL 2000,我的 text file 类似如下 :
Text file name = text1.txt
Name              Age              Position
AAA ...


解决方法很简单.
DoCmd 只能用在 access, sql server 你只要写个普通的 sql server 连接就可以.
最容易的办法就是用 DSN, internet 上可以找到很多.

然后只要把文件里的每一行跟着 maximum characters 读取, 再用 INSERT 就可以了.


Dim db AS New ADODB.Connection
db.Open "DSN=mydsn;UID=myid;PWD=mypassword"
db.BeginTrans

While Not EOF(1)
  ...
  ...
  ...
  db.Execute sql
Wend

db.CommitTrans

db.Close
Set db = Nothing
回复

使用道具 举报

发表于 22-12-2004 11:18 AM | 显示全部楼层
goatstudio 于 22-12-2004 09:24 AM  说 :


解决方法很简单.
DoCmd 只能用在 access, sql server 你只要写个普通的 sql server 连接就可以.
最容易的办法就是用 DSN, internet 上可以找到很多.

然后只要把文件里的每一行跟着 maximum characters 读 ...


thx u.., i try it now!!
回复

使用道具 举报

发表于 22-12-2004 03:49 PM | 显示全部楼层
goatstudio 于 22-12-2004 09:24 AM  说 :


解决方法很简单.
DoCmd 只能用在 access, sql server 你只要写个普通的 sql server 连接就可以.
最容易的办法就是用 DSN, internet 上可以找到很多.

然后只要把文件里的每一行跟着 maximum characters 读 ...



嘿, 以下是我try了你的coding加我的coding写出来的方法 (还是有点儿乱!) : 这linking好象对MS SQL 2000 有反应了, 可是还是有bug, 不好意思,还是不够经验。

New coding :
Sub ImportTextFile3()
Dim LineData As String
Dim Name As String
Dim Age As String
Dim Pos As String
Dim db As New ADODB.Connection
db.Open "DSN=Emp;UID=123;PWD=123"
db.BeginTrans

Set cncurrent = CurrentProject.Connection
Set rsDiag = New ADODB.Recordset

Open "C:\text1.txt" For Input As #1

strsql = "Select * from EmpProfile"
rsDiag.Open strsql, cncurrent, adOpenDynamic,
adLockOptimistic
Do While Not EOF(1)
' Read a line of data.

Line Input #1, LineData
Name = Trim(Mid(LineData, 2, 30))
Age = Trim(Mid(LineData, 33, 3))
Pos = Trim(Mid(LineData, 37, 20))

rsDiag.AddNew
rsDiag!Name = Name
rsDiag!Age = Age
rsDiag!Position = Pos
rsDiag.Update
  db.Execute sql
Loop
' Close the data file.
Close #1
rsDiag.Close

db.CommitTrans

db.Close
Set db = Nothing
End Sub


其实DSN我早就setting好了, 而且我肯定它操作正常, 因为除了这import的form之外, 我还做了其他象login form, edit form, add new form...., 等等。这些form也都call from 同一个MS SQL 2000 DATABASE, 也都成功add new, update 到了!! 唯有这个import form 还是有问题!

"rsDiag.Open strsql, cncurrent, adOpenDynamic,
adLockOptimistic " 象这行coding还是在call MS Access 的 , 因为它要通过"rsDiag"来开启 strsql(SQL Daatabase ,EPmprofile table) 和 cncurrent (Text file), 象您建议我的coding, 我就看不到它在哪里叫我的table(sorry,学艺不精),可以帮我看一看吗?

以下是出现的bug :
Run-time error '3709' :
The connection cannot be used to perform this operation. It is either closed or invalid in this context.

研究了好久,还是没办法!
回复

使用道具 举报

发表于 22-12-2004 04:14 PM | 显示全部楼层
1. rsDiag 已经不需要
2. 你的 db 没有执行任何 sql... 因为 sql 这 variable 是空的. 你需要用你所得到的 variable 来组合一个 INSERT statement, 例如: INSERT INTO table_name...

db.Execute sql
sql 就是你的 sql string.
回复

使用道具 举报

发表于 22-12-2004 04:43 PM | 显示全部楼层
我明白你的意思了,试试看吧!! 谢谢哦!
回复

使用道具 举报

 楼主| 发表于 28-12-2004 10:30 AM | 显示全部楼层
還有就是當你們要select a data from a table but u don't want the format date is mm/dd/yyyy.

那你們的scrtip是怎樣呢.??

set formate date = dd/mm/yyy
select * from tablename
where postdate = ''

是不是這樣呢?
回复

使用道具 举报

发表于 28-12-2004 10:38 AM | 显示全部楼层
很简单.
SELECT CONVERT(varchar, my_date, 103) AS new_date FROM tablename
回复

使用道具 举报


ADVERTISEMENT

发表于 28-12-2004 01:02 PM | 显示全部楼层
goatstudio 于 28-12-2004 10:38 AM  说 :
很简单.
SELECT CONVERT(varchar, my_date, 103) AS new_date FROM table ...



string conn_str = "Data Source=(local);Initial Catalog=abc;Integrated Security=SSPI" ;
                        string mySelectQuery = "SELECT CONVERT(varchar, my_date, 103) AS new_date FROM tablename WHERE culomnname='abc'" ;
                        SqlConnection myConnection = new SqlConnection(conn_str);
                        SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
                        myConnection.Open();
                        SqlDataReader myReader;
                        myReader = myCommand.ExecuteReader();

                    string strResult="";

                        while (myReader.Read())
                        {
                                strResult=(myReader.GetSqlString(0).ToString());
                        }


但是strResult 还是 mm/dd/yyyy......
回复

使用道具 举报

 楼主| 发表于 28-12-2004 01:41 PM | 显示全部楼层
我的script是run在sql server裡面的....
回复

使用道具 举报

发表于 28-12-2004 02:07 PM | 显示全部楼层
mouyanseng 于 28-12-2004 01:02 PM  说 :



string conn_str = "Data Source=(local);Initial Catalog=abc;Integrated Security=SSPI" ;
                        string mySelectQuery = "SELECT CONVERT(varchar, my_date, 103) AS new_date FROM tablen ...


有点奇怪.

1. 原始 data 是什么?
2. 有没有在 query analyzer 那里试一下?
回复

使用道具 举报

发表于 28-12-2004 02:08 PM | 显示全部楼层
手語 于 28-12-2004 01:41 PM  说 :
我的script是run在sql server裡面的....


你有没有试试看呢?
在 query analyzer 那里试看吧.
这 syntax 不管在那里都可以用的.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 25-5-2024 01:06 AM , Processed in 0.165714 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表