Lm th? no ? s? d?ng k? t? ?i di?n trong m?t h?nh th?c InfoPath truy v?n khi rng bu?c ? m?t ngu?n d? li?u ADO

D?ch tiu ? D?ch tiu ?
ID c?a bi: 826992 - 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

Microsoft Office InfoPath lm rng bu?c ? Microsoft SQL Server hay Microsoft Access n gi?n. InfoPath c th? t? ?ng t?o ra b?ng n gi?n, tr?c ti?p truy v?n t?i m?t c s? d? li?u SQL ho?c m?t c s? d? li?u truy c?p b?ng cch s? d?ng Microsoft ActiveX Data Objects (ADO). Sau , InfoPath cho php cc k?t qu? c?a cc truy v?n ?c hi?n th? v s?a trong cc h?nh th?c.

Lm cho cc truy v?n nng cao hn, InfoPath cho m?t s? phng php l?p tr?nh c s?n cho ng?i dng nng cao ho?c cc nh pht tri?n. Nh?ng phng php l?p tr?nh cho php ng?i dng nng cao ho?c cc nh pht tri?n ? xy d?ng cc h?nh th?c c th? th?c hi?n m?t truy v?n ty ch?nh m s? d?ng c php SQL ph?c t?p hn. M?t v d? v? m?t truy v?n ty ch?nh th?ng s? d?ng m?t nhn v?t k? t? ?i di?n ? t?m th?y h? s ph?n kh?p v?i tiu ch c? th?.

Cc b?c sau y cho th?y lm th? no ? s? d?ng qu?n l? m? trong InfoPath ? th?c hi?n m?t t?m ki?m nhn v?t k? t? ?i di?n trong m?t b?ng SQL ho?c trong m?t b?ng truy c?p b?ng cch s? d?ng cc ADOAdapter ?i t?ng.

THNG TIN THM

InfoPath cho php b?n c m?t k?t n?i d? li?u truy v?n nh l m?tAdoQueryConnection ?i t?ng. i?u ny s? cho b?n phng php ? l?y v ?t thng tin v? cc m?c sau y:
  • K?t n?i chu?i
  • Vn b?n l?nh SQL
  • Gi tr? l?i qu th?i gian
B?ng cch s? d?ng cc AdoQueryConnection?i t?ng, b?n c th? thay ?i m?t l?nh SQL ? th?c hi?n cc ho?t ?ng ph?c t?p hn, ch?ng h?n nh m?t truy v?n s? d?ng k? t? ?i di?n.

Thng tin trong bi vi?t ny p d?ng cho c s? d? li?u SQL v c s? d? li?u truy c?p. Cc v d? sau s? d?ng c s? d? li?u Northwind ?c bao g?m v?i Microsoft Office Access 2007 v Microsoft Office Access 2010.

T?o c s? d? li?u

N?u b?n ? khng ?c dng c s? d? li?u m?u Northwind t? phin b?n c?a InfoPath b?n, t?o c s? d? li?u t?i ?a phng. thc hin vic nay, hay lam theo nhng bc sau:

  1. B?t ?u truy c?p Microsoft Office.
  2. Trong ccS?n m?um?c, ch?nM?u m?u.
  3. Ch?n cc Northwind c s? d? li?u, v sau nh?p voTao.

Thi?t k? m?t h?nh th?c truy v?n c s? d? li?u

Ph?n ny m t? cch thi?t k? m?t h?nh th?c truy v?n trong InfoPath. V d? ny s? d?ng cc nh cung c?p b?ng t? c s? d? li?u Northwind. ? xy d?ng m?t h?nh th?c truy v?n b?ng ny, lm theo cc b?c ?c cung c?p cho cc phin b?n c?a InfoPath.

InfoPath 2010

T?o m?u h?nh th?c, v sau thi?t l?p ngn ng? m? tiu b?n m?u ? C#. thc hin vic nay, hay lam theo nhng bc sau:
  1. B?t ?u InfoPath Designer 2010.
  2. Trong ccNng cao m?u Templatesm?c, ch?nCo? so? du? lie?u, sau b?m Thi?t k? m?u.
  3. Trong thu?t s? k?t n?i d? li?u, b?m Ch?n c s? d? li?u.
  4. Xc ?nh th m?c m b?n lu c s? d? li?u Northwind, ch?n t?p tin Northwind.accdb v sau nh?p vo M?.
  5. Trong cc Ch?n b?ng c?a s?, di chuy?n ?n d?i cng c?a danh sch, ch?n cc Cc nh cung c?p b?ng, v sau nh?p vo Ok.
  6. ?m b?o r?ng ch? c cc l?nh v?c sau y ? ?c ch?n trong cc Cc nh cung c?p b?ng:
    • ID
    • Cng ty
    • Last_Name
    • First_Name
    • Job_Title
    • Business_Phone
  7. Nh?p vo Ti?p theo.
  8. Nh?p vo K?t thchon thnh thu?t s? k?t n?i d? li?u.
  9. Trong cc Cc l?nh v?cc?a s?, m? r?ng ccdataFieldsnt, v sau ko cc ti?n chd:suppliersnt h?p d?i ccCh?y truy v?nnt.
  10. Khi b?n ?c nh?c, b?m vo ? ch?n L?p i l?p l?i b?ng.
  11. Trong ccCc l?nh v?cc?a s?, m? r?ng ccqueryFieldsnt, v sau ko cc ti?n chq: nh cung c?p nt h?p d?i ccK? l?cnt. (i?u ny s? t? ?ng thm m?t ph?n c i?u khi?n.)
  12. Theo ccNha phat trintab, b?m voNgn ng?.
  13. Trong ccNgn ng? l?p tr?nhAdran, d?iD?ng m?u m? ngn ng?, ch?n C#, sau b?mOk.

InfoPath 2007

T?o m?u h?nh th?c. thc hin vic nay, hay lam theo nhng bc sau:
  1. Kh?i ?ng InfoPath 2007.
  2. Trong ngn d?n h?ng c?a cci?n vo m?t m?u h?p tho?i h?p, b?m vo Thi?t k? m?t m?u h?nh th?c.
  3. Trong cc Thi?t k? m?t m?u h?nh th?c c?a s?, Nh?p vo Tr?ng, sau b?m Ok.
  4. Trn cc Cng cu tr?nh n, nh?p vo D? li?u Kt ni, sau b?m Thm. Cc D? li?u K?t n?i c?a s? m? ra.
  5. Trong cc K?t n?i d? li?u c?a s?, nh?n vo y ? ch?n cc T?o k?t n?i m?i t?i h?p ki?m tra, nh?n vo y ? ch?n cc Nh?n d? li?u ki?m tra h?p v b?mTi?p theo.
  6. Nh?n vo y ? ch?n cc C s? d? li?u (Microsoft SQL Server ho?c Microsoft Office Access ch?) ki?m tra h?p v b?mTi?p theo.
  7. Nh?p vo Ch?n c s? d? li?u.
  8. Xc ?nh th m?c m b?n lu c s? d? li?u Northwind, ch?n th m?c v sau nh?p vo M?.
  9. Trong cc Ch?n b?ngh?p tho?i, di chuy?n ?n d?i cng c?a danh sch, ch?n ccCc nh cung c?pb?ng, v sau nh?p voOk.
  10. Trong cc C?u trc d? li?u ngu?ndanh sch, h?y ch?c ch?n r?ng ch? cc tiu ? c?t sau y ? ?c ch?n:
    • ID
    • Cng ty
    • First_Name
    • Last_Name
    • Job_Title
    • Business_Phone
  11. Nh?p voTi?p theo.
  12. Nh?p vo Thi?t k? d? li?u Xem tr?c, v sau Nh?p vo K?t thc ? thot kh?i thu?t s? thi?t l?p ngu?n d? li?u v xy d?ng cc h?nh th?c m?c ?nh.
  13. Trong cc Ngu?n d? li?u nhi?m v? ngn, b?m p vodataFields.
  14. Di chuy?n cc d:suppliers nt ? cc D? li?u xem bi?u m?u.
  15. Khi b?n ?c nh?c, thm d:suppliers nh m?t L?p i l?p l?i b?ng.
  16. Trn cc Xem tr?nh n, nh?p vo Qu?n l? Ch xem.
  17. Trong cc Ch xem nhi?m v? ngn, b?m vo ccTruy vn xem.
  18. Trn cc Cng cu tr?nh n, nh?p vo H?nh th?c ty ch?n.
  19. Trong cc Th? lo?i danh sch, b?m vo L?p tr?nh.
  20. Trong cc D?ng m?u m? ngn ng? h?p, b?m vo C#, sau b?m Ok.

Thay ?i h?nh th?c ? ch?y m?t truy v?n ty ch?nh

Ph?n ny m t? lm th? no ? t?m ki?m cc h? s c gi tr? m gi?ng v?i chu?i t?m ki?m c?a b?n nhng khng ph h?p v?i chu?i chnh xc. ? t?m ki?m cc h? s c gi tr? tng t?, b?n c th? s? d?ng m?t chu?i k? t? k? t? ?i di?n v ccGI?NG NHtuyn b? trong m?t truy v?n SQL. Khi k? t? ?i di?n ky t ket hp chu?i v ccGI?NG NHtuyn b? ?c s? d?ng v?i nhau, h? c th? t?m th?y h? s d?a trn cc tiu ch t?m ki?m nhn v?t k? t? ?i di?n. Nh?ng h? s ny sau quay tr? l?i InfoPath.

? thay ?i h?nh th?c ? ch?y m?t truy v?n ring c?a ccTiu ? cng vi?ctr?ng trong InfoPath 2010 ho?c trong InfoPath 2007, h?y lm theo cc b?c sau:

  1. Trong ch? ? thi?t k?, b?m chu?t ph?i vo cc Ch?y truy v?n nt, v sau nh?p vo Thu?c tnh nt.
  2. Th?c hi?n nh?ng thay ?i sau:
    • Thay ?i cc Hnh ?ng nt ?Quy t?c v tu? ch?nh m?
    • Thay ?i cc Nh?n hi?u?Ch?y truy v?n
    • Thay ?i cc ID?btnQuery
  3. B?m vo cc Ch?nh s?a h?nh th?c m? nt ? p d?ng nh?ng thay ?i, v sau b?t ?u s? d?ng cc cng c? ph?ng thu tr?c quan cho cc ?ng d?ng tr?nh so?n th?o. N s? m? ra cc btnQuery "Clicked" s? ki?n x? l?.
  4. Thay th? cc b?nh lu?n "/ / vi?t m? c?a b?n ? y" v?i o?n m? sau:
    //Create an XPathNavigator object for the main data source
    XPathNavigator xnMain = this.MainDataSource.CreateNavigator();
     
    //Create an AdoQueryConnection from the main data source by "casting" the default
    //data connection to an "AdoQueryConnection"
    AdoQueryConnection cn = (AdoQueryConnection)this.DataConnections["Main connection"];
     
    //Obtain the default SQL command for the form.
    string strOrigSQLCommand = cn.Command.ToString();
     
     
     
    // Obtain the query node that you want to change.
    XPathNavigator xnSuppliersQuery = xnMain.SelectSingleNode("/dfs:myFields/dfs:queryFields/q:Suppliers", this.NamespaceManager);
     
    //Obtain the text that was entered for the wildcard character search, and then clear the current query parameter so that InfoPath will leave the current query parameter blank.
    string strJobTitle = xnSuppliersQuery.SelectSingleNode("@Job_Title", this.NamespaceManager).Value;
    xnSuppliersQuery.SelectSingleNode("@Job_Title", this.NamespaceManager).SetValue(string.Empty);
     
    //Have InfoPath construct an SQL command that is based on all other field values.
    string strMySQLCommand = cn.BuildSqlFromXmlNodes(xnSuppliersQuery);
     
    //Save the other query items, and then clear the other query items before the next query.
    string strSupplierID = xnSuppliersQuery.SelectSingleNode("@ID", this.NamespaceManager).Value;
    xnSuppliersQuery.SelectSingleNode("@ID", this.NamespaceManager).SetValue(string.Empty);
    string strCompany = xnSuppliersQuery.SelectSingleNode("@Company", this.NamespaceManager).Value;
    xnSuppliersQuery.SelectSingleNode("@Company", this.NamespaceManager).SetValue(string.Empty);
    string strLastName = xnSuppliersQuery.SelectSingleNode("@Last_Name", this.NamespaceManager).Value;
    xnSuppliersQuery.SelectSingleNode("@Last_Name", this.NamespaceManager).SetValue(string.Empty);
    string strFirstName = xnSuppliersQuery.SelectSingleNode("@First_Name", this.NamespaceManager).Value;
    xnSuppliersQuery.SelectSingleNode("@First_Name", this.NamespaceManager).SetValue(string.Empty);
    string strBusPhone = xnSuppliersQuery.SelectSingleNode("@Business_Phone", this.NamespaceManager).Value;
    xnSuppliersQuery.SelectSingleNode("@Business_Phone", this.NamespaceManager).SetValue(string.Empty);
     
    //Add Job_Title to the query so that Job_Title can support wildcard characters.
    if (strJobTitle != string.Empty)
    {
           if (strMySQLCommand != string.Empty)
                  strMySQLCommand += " AND ";
     
           //Check whether the user entered the wildcard character (%) as part of the title.
    if(strJobTitle.Contains("%"))
                 strMySQLCommand += "[Job Title] LIKE '" + strJobTitle + "'";
           else
                 strMySQLCommand += "[Job Title] LIKE '" + strJobTitle + "%'";               
    }
     
    //Construct the full query string.
    string strSQLQuery = strOrigSQLCommand;
    if (strMySQLCommand != string.Empty)
    strSQLQuery += " WHERE " + strMySQLCommand;
     
    //Set the command and run the query.
    cn.Command = strSQLQuery;
    cn.Execute();
     
    //Restore all the user entries to the Query fields so that the user entries will 
    //be available if you want to change and to rerun the query.
    xnSuppliersQuery.SelectSingleNode("@ID", this.NamespaceManager).SetValue(strSupplierID);
    xnSuppliersQuery.SelectSingleNode("@Company", this.NamespaceManager).SetValue(strCompany);
    xnSuppliersQuery.SelectSingleNode("@Last_Name", this.NamespaceManager).SetValue(strLastName);
    xnSuppliersQuery.SelectSingleNode("@First_Name", this.NamespaceManager).SetValue(strFirstName);
    xnSuppliersQuery.SelectSingleNode("@Job_Title", this.NamespaceManager).SetValue(strJobTitle);
    xnSuppliersQuery.SelectSingleNode("@Business_Phone", this.NamespaceManager).SetValue(strBusPhone);
     
    //Restore the default table command (for the next time).
    cn.Command = strOrigSQLCommand;
     
    //Clean up
    xnMain = null;
    cn = null;
    xnSuppliersQuery = null;
  5. Xy d?ng d? n b?ng cch b?m vo cc Xy d?ngm?c tr?nh n v sau nh?p vo Xy d?ngtn d? n.
  6. Lu cc thay ?i, v sau tr? v? InfoPath.

Ki?m tra m?

M?u m? ?c cung c?p trong cc th? t?c tr?c cho php b?n th?c hi?n t?m ki?m nhn v?t k? t? ?i di?n c?a ccTiu ? cng vi?c tr?ng trong cc Cc nh cung c?p b?ng. B?ng cch cung c?p m?t truy v?n t?m ki?m nh Bn hng %, t?t c? h? s tr? l?i s? c ?a ch? lin l?c trong m?t v? tr bn hng. Nh?ng ?a ch? lin l?c c th? l m?t ?i di?n, m?t ng?i qu?n l? ho?c m?t tc nhn mi?n l h? s c?a h? p ?ng cc tiu ch t?m ki?m c?aBn hng %. ?a ch? lin l?c m khng c "Bn hng" trong Tiu ? cng vi?c tr?ng ?c l?c.


Ki?m ch?ng r?ng t?t c? h? s tr? l?i c ?a ch? lin l?c ? m?t v? tr bn hng, h?y lm theo cc b?c sau:
  1. Cho InfoPath 2010:Trn ccTrang ch?tab trn Ribbon, nh?p voXem tr?c.
    Cho InfoPath 2007:Trn thanh cng c?, nh?p Xem tr?c, sau b?mH?nh th?c.
  2. Trong cc Tiu ? cng vi?c truy v?n tr?ng, lo?i Bn hng %.
  3. Nh?p vo Ch?y truy v?n.

Cc h? s ?c tr? v? b?i tu? ch?nh truy v?n c?a b?n l t?t c? cc ?a ch? lin l?c ? m?t v? tr bn hng.

Thu?c tnh

ID c?a bi: 826992 - L?n xem xt sau cng: 29 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Office InfoPath 2007
  • Microsoft Office InfoPath 2003
T? kha:
kbhowto kbmt KB826992 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:826992

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