我是个新手...刚刚想弄个ADDNEW于是就做成了这样 Private Sub Command1_Click() With Adodc1 .Recordset.AddNew "标题", bttex.Text .Recordset.AddNew "文章", wztex.Text .Recordset.UpdateBatch End With End Sub 但是如果这样写的话,会在数据库的不同列中出现输入的东西,怎么样才可以让他在同一列中添加文字啊?
VBçAddNewæ¯æAddNew æ¹æ³ (ADO)ï¼æ¯ä¸ºå¯æ´æ°ç Recordset 对象å建æ°è®°å½ã
AddNew æ¹æ³ (ADO)ï¼ä¸ºå¯æ´æ°ç Recordset 对象å建æ°è®°å½ã
Recordset 对象 (ADO)
Recordset 对象表示çæ¯æ¥èªåºæ¬è¡¨æå½ä»¤æ§è¡ç»æçè®°å½å
¨éãä»»ä½æ¶åï¼Recordset
对象ææçå½åè®°å½å为éåå
çå个记å½ã
AddNew æ¹æ³èä¾
该èä¾ä½¿ç¨ AddNew æ¹æ³åå»ºå ·ææå®å称çæ°è®°å½ãPublic Sub AddNewX()
Dim cnn1 As ADODB.Connection
Dim rstEmployees As ADODB.Recordset
Dim strCnn As String
Dim strID As String
Dim strFirstName As String
Dim strLastName As String
Dim booRecordAdded As Boolean
' æå¼è¿æ¥ã
Set cnn1 = New ADODB.Connection
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=;"
cnn1.Open strCnn
' æå¼ Employee 表ã
Set rstEmployees = New ADODB.Recordset
rstEmployees.CursorType = adOpenKeyset
rstEmployees.LockType = adLockOptimistic
rstEmployees.Open "employee", cnn1, , , adCmdTable
' ä»ç¨æ·è·åæ°æ®ï¼éå ID çæ ¼å¼åºä¸ºï¼
' åãä¸é´ååå§çä¸ä¸ªé¦åæ¯ï¼
' äºä½æ°åï¼ä»¥åæ§å«æ è¯ M æ Fã
' ä¾å¦ï¼Bill Sornsin çéå ID 为ï¼B-S55555Mã
strID = Trim(InputBox("Enter employee ID:"))
strFirstName = Trim(InputBox("Enter first name:"))
strLastName = Trim(InputBox("Enter last name:"))
' åªå¨ç¨æ·è¾å
¥å§ååä¹åè¿è¡ã
If (strID <> "") And (strFirstName <> "") _
And (strLastName <> "") Then
rstEmployees.AddNew
rstEmployees!emp_id = strID
rstEmployees!fname = strFirstName
rstEmployees!lname = strLastName
rstEmployees.Update
booRecordAdded = True
' æ¾ç¤ºæ°æ·»å çæ°æ®ã
MsgBox "New record: " & rstEmployees!emp_id & " " & _
rstEmployees!fname & " " & rstEmployees!lname
Else
MsgBox "Please enter an employee ID, " & _
"first name, and last name."
End If
' å é¤æ°è®°å½ï¼å 为è¿åªæ¯æ¼ç¤ºã
cnn1.Execute "DELETE FROM employee WHERE emp_id = '" & strID & "'"
rstEmployees.Close
cnn1.Close
End Sub