查看: 824|回复: 3
|
关于vb.net database 的问题
[复制链接]
|
|
如何connect to database (Ms Access)?
Public conn As ADODB.Connection
conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "C:\FinalProject\Property.mdb" & ";"
conn.Open()
这样正确吗?
为什么我不能add record to database?
Dim rep As ADODB.Recordset
rep = conn.Execute("SELECT * FROM report")
While Not rep.EOF
If rep(0).Value <> "" Then
tempnum = rep(0).Value
End If
user1.MoveNext()
End While
tempnum = tempnum + 1
rep.AddNew()
rep(1).Value = fname1
rep(2).Value = addr1
rep(3).Value = pcode1
rep(4).Value = Tenure1
rep(5).Value = reYear
rep(6).Value = 7
rep(7).Value = lsize
rep(8).Value = "-"
rep(9).Value = ltotal
rep.Update()
rep.Close()
谁可以帮帮我? |
|
|
|
|
|
|
|
发表于 28-5-2006 05:37 PM
|
显示全部楼层
原帖由 momo99t 于 28-5-2006 06:54 AM 发表
如何connect to database (Ms Access)?
Public conn As ADODB.Connection
conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Da ...
我看来看去... 你的 while loop 是用来做什么的呢?
你的 user1.MoveNext() 的 user1 这 recordset 是那里来的呢?
既然只是纯粹加入一个新的资料...
Public conn As ADODB.Connection
conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "C:\FinalProject\Property.mdb" & ";"
conn.Open()
conn.Execute ("INSERT INTO ...")
conn.Close()
Set conn = Nothing |
|
|
|
|
|
|
|
楼主 |
发表于 28-5-2006 06:26 PM
|
显示全部楼层
after i compile 它出this error
Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.
为什么会这样??? |
|
|
|
|
|
|
|
发表于 29-5-2006 02:21 AM
|
显示全部楼层
VB 和 VB.Net 的 ADO 应该是一样吧
这个是我 VB 的方法,VB.Net 没试过
connection 应该是对了
我就从 recordset 开始
Set rep = New ADODB.Recordset
rep.Open "SELECT * FROM report", conn, adOpenKeySet, adLockPessimistic
rep.AddNew
...
rep.Update
rep.Close
我猜你是少了 adOpenKeySet & adLockPessimistic 还是 conn.CursorLocation = adUseClient 而已 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|