Lm th? no ?: T?o m?t c s? d? li?u, m?t b?ng, v ch?y m?t truy v?n (SQL Server CE m?u)

D?ch tiu ? D?ch tiu ?
ID c?a bi: 320785 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

Bi vi?t ny ch?a m?t b?c theo b?c m?u m t?o ra c s? d? li?u, m?t b?ng, v thm b?n ghi vo c s? d? li?u SQL Server CE. Cc m?u c?ng truy v?n b?ng m?i v hi?n th? cc b?n ghi trong b?ng.

SQL Server CE m?u

  1. M? m?t d? n m?i trong Microsoft nhng Visual Basic. Form1 ?c t?o ra theo m?c ?nh.
  2. Thm ba nt l?nh ? Form1.
  3. Thay ?i cc ch thch cho nt l?nh ?t tn Command1 ? T?o c s? d? li?u. Thay ?i cc ch thch cho nt l?nh ?t tn Command2 ? T?o b?ng. Thay ?i cc ch thch cho nt l?nh ?t tn Command3 ? Ch?y truy v?n.
  4. Trn cc D an tr?nh n, nh?p vo Tham khao. H?y ch?c ch?n r?ng ti li?u tham kh?o sau y ? ?c ch?n:
    Microsoft CE ADO Ext. 3.1 cho Laser Mouse
    Microsoft CE SQL Server Control 1.0
    Microsoft CE ADO Control 3.1
  5. ? ?m b?o r?ng ADO Microsoft cho Windows CE SDK (ADOCE) v SQL Server CE thnh ph?n ?c t?i xu?ng cho thi?t b?, trn cc D an tr?nh n, nh?p vo Thu?c tnh. Trn cc T?ng qut tab, b?n s? th?y m?t C?p nh?t cc thnh ph?n ke tiep. Trong cc T?n s? cho cc c?u ph?n C?p Nh?t h?p combo, nh?n vo y ? ch?n Lun lun cho t?n s?. Trong cc Thnh ph?n C?p Nh?t ph?n, nh?n vo y ? ch?n c? cc Th?i gian ch?y t?p tin v cc Cc thnh ph?n d? n h?p ki?m.

Lm th? no ? t?o ra m?t c s? d? li?u

? t?o c s? d? li?u, s? d?ng m?u m? ny:

Sao chp, v sau dn o?n m? sau vo cc Command1_Click s? ki?n:
Dim cat As ADOXCE.Catalog
Set cat = CreateObject("ADOXCE.Catalog.3.1")
cat.Create "Provider=Microsoft.SQLSERVER.OLEDB.CE.1.0; data source=\DATAB.sdf"
MsgBox "Database Created"
				


Lm th? no ? t?o ra m?t b?ng

? t?o m?t b?ng, s? d?ng m?u m? ny:

Sao chp, v sau dn o?n m? sau vo cc Command2_Click s? ki?n:
Dim str_Connection As String
Dim cn As ADOCE.Connection

str_Connection = "Provider=Microsoft.SQLSERVER.OLEDB.CE.1.0; data source=\DATAB.sdf"
Set cn = CreateObject("ADOCE.Connection.3.1")
cn.Open str_Connection
cn.Execute "Create table table1(id int NOT NULL, field1 nvarchar(1))"
cn.Execute "CREATE UNIQUE INDEX idx1 ON table1(id)"
cn.Execute "insert table1 values (1, 'A')"
cn.Execute "insert table1 values (2, 'B')"
cn.Execute "insert table1 values (3, 'C')"
cn.Close
Set cn = Nothing
MsgBox "Table Created"
				

Lm th? no ? truy v?n m?t b?ng

? truy v?n b?ng b?n t?o ra tr?c y, h?y lm theo cc b?c sau:
  1. Sao chp, v sau dn o?n m? sau vo cc Command3_Click s? ki?n:
    Dim cn As ADOCE.Connection
    Dim rs As ADOCE.Recordset
    Set cn = CreateObject("ADOCE.Connection.3.1")
    Set rs = CreateObject("ADOCE.Recordset.3.1")
    cn.Open "Provider=Microsoft.SQLSERVER.OLEDB.CE.1.0; data source=\DATAB.sdf"
    rs.Open "select * from table1 where field1='A'", cn, adOpenKeyset, adLockReadOnly
    Dim x As Integer
    x = 0
    For x = 0 To rs.RecordCount - 1
        MsgBox rs(1).Value
        rs.MoveNext
    Next
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    					

  2. Lu d? n, v sau ch?y cc d? n ho?c thng qua m?t tr?nh gi? l?p ho?c thi?t b?.
  3. B?m vo cc T?o c s? d? li?u nt l?nh.
  4. B?m vo cc T?o b?ng nt l?nh.
  5. B?m vo cc Ch?y truy v?n nt l?nh. Lu ? th h?p m hi?n th? cc k? t? "A".

THAM KH?O

SQL Server CE sch tr?c tuy?n; ch? ?: "L?i x? l?"

? thm thng tin, h?y truy c?p trang Web Microsoft sau y:

G? r?i v?n ? k?t n?i CE my ch? SQL

SQL Server CE 1,1 gi d?ch v? 1 C?p Nh?t

Thu?c tnh

ID c?a bi: 320785 - L?n xem xt sau cng: 27 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft SQL Server 2000 Windows CE Edition
T? kha:
kbgraphxlink kbhowto kbhowtomaster kbmt KB320785 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:320785
Khc t Ni dung trong C s Kin thc Khng con c h tr
Bi vi?t ny ni v? cc s?n ph?m m Microsoft khng c?n h? tr? n?a. Do , bi vi?t ny ?c cung c?p "nguyn b?n" v s? khng ?c c?p nh?t.

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com