Click here to Skip to main content
15,884,062 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i created the .dot file than saved as template .
this template file i have to show bookmark by paticular name and
location.so i have to populate the sql table field in the template file so i
can set field name and location from bookmark.

but i dont kw how to populate the sql table field in the template file
in C# windows forms??so how can i do???

[Updated tags to include Word]
Posted
Updated 6-Mar-12 17:28pm
v2
Comments
sadhana4 6-Mar-12 21:43pm    
rivate Sub Document_Open()
Dim Conn As New ADODB.Connection
Dim rsInvoices As New Recordset
Dim objDoc As Document
Dim objTable As Table
Dim strUserTemplates As String
Dim strConnection As String
Dim strCustomer As String
Dim strDBPath As String
Dim strSQL As String
Dim intNumRows As Integer
Dim i As Integer

On Error Resume Next

strDBPath = "C:\Program Files\Microsoft OfficeXP" & _
"\Office10\Samples\Northwind.mdb"

' Open a connection to the Northwind database.
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"Data Source=" & strDBPath

Conn.Open strConnection

strSQL = "SELECT * FROM Invoices " & _
"WHERE (((Orders.ShipName)='QUICK-Stop'))"

rsInvoices.Open strSQL, Conn, adOpenStatic, adLockReadOnly

strUserTemplates = Options.DefaultFilePath(wdUserTemplatesPath)

Set objDoc = Documents.Add(strUserTemplates & _
"\Simple Invoice.dot")

' Retrieve and set company information.
SetBookmark ActiveDocument, "CoName", _
rsInvoices("Customers.CompanyName").Value
SetBookmark ActiveDocument, "CoAddress", _
rsInvoices("Address").Value
SetBookmark ActiveDocument, "CoCity", _
rsInvoices("City").Value

' To handle Nulls in this field.
If IsNull(rsInvoices("Region").Value) Then
SetBookmark ActiveDocument, "CoState", _
""
Else
SetBookmark ActiveDocument, "CoState", _
rsInvoices("Region").Value
End If
SetBookmark ActiveDocument, "CoZip", _
rsInvoices("PostalCode").Value

' Retrieve and set Bill To information.
SetBookmark ActiveDocument, "BillToName", _
rsInvoices("Salesperson").Value
SetBookmark ActiveDocument, "BillToCompany", _
rsInvoices("ShipName").Value
SetBookmark ActiveDocument, "BillToAddress", _
rsInvoices("ShipAddress").Value
SetBookmark ActiveDocument, "BillToCity", _
rsInvoices("ShipCity").Value

' To handle Nulls in this field
If IsNull(rsInvoices("ShipRegion").Value) Then
SetBookmark ActiveDocument, "BillToState", _
""
Else
SetBookmark ActiveDocument, "BillToState", _
rsInvoices("ShipRegion").Value
End If
SetBookmark ActiveDocument, "BillToZip", _
rsInvoices("ShipPostalCode").Value


Set objTable = ActiveDocument.Tables(3)

i = 1

objTable.Cell(i, 1).Range.Text = "Description"
objTable.Cell(i, 2).Range.Text = "Amount"

Do While Not rsInvoices.EOF

i = i + 1

objTable.Cell(i, 1).Range.Text = rsInvoices("ProductName")
objTable.Cell(i, 2).Range.Text = Format(rsInvoices("ExtendedPrice"), "Currency")

rsInvoices.MoveNext
Loop
‘ Clean up.
Set objDoc = Nothing
Set objTable - Nothing

End Sub

Public Sub SetBookmark(objDoc As Document, sBookmark As String, sValue As String)

If objDoc.Bookmarks.Exists(sBookmark) Then

objDoc.Bookmarks(sBookmark).Range.Text = sValue

End If

End Sub
i have vb code .but i dont know how to do in C# windows
sadhana4 7-Mar-12 2:48am    
how to do this type of coding in C# windows froms???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900