you can do this with a reader,
I do that for a table in drawing, see the code
the code run in the 2 directions
I take the data from the SQL
or I write in the SQL
It's in french, if you don't understand, I'll translate
SyntaxEditor Code Snippet
AddReference "System.Data"
AddReference "System.Core"
AddReference "System.Xml"
'Imports System.Data.OleDb
Imports System.Data
Imports System.Xml
Imports System.Data.SqlClient
SyntaxEditor Code Snippet
'++++++++++++++++EXTRACTION N° DE PROJET++++++++++++++
Dim NomFi As String
Dim NumProj As String
Dim DecFi As Object
NomFi = ThisDoc.FileName(False)
DecFi = Split(NomFi, "-")
NumProj = DecFi(0)
MessageBox.Show(NumProj, "Title")
'+++++++++++++++++++++LIEN SQL+++++++++++++++++++++
Dim myConn As SqlConnection
Dim myCmd As SqlCommand
Dim myReader As SqlDataReader
Dim results As String
Dim Req As String
Dim ReqInsert As String
'Definition de la connexion
myConn = New SqlConnection("Data Source = SRV-SQL ;Initial Catalog = SqlBase1 ;User Id = sa ;Password = 123 ; ")
'requete d'interrogation
Req = "SELECT Codelancement,DateCreationLct FROM HART_PLAN_LCT LIMIT1 WHERE DesignationLct4='" + NumProj + "' ORDER BY DateCreationLct DESC"
myCmd = myConn.CreateCommand
myCmd.CommandText = Req
'Ouverture de la connexion
myConn.Open()
myReader = myCmd.ExecuteReader()
'Controle de la presence de donnees dans le reader
'If myReader.HasRows = False Then
'MessageBox.Show("faux", "Title")
'Else
'Inscrire le resultat de la requete dans une chaine de caracteres
'Do While
'myReader.Read()
'results = myReader.GetString(0)
' Loop
'Affichage du resultat.
'MsgBox(results)
'++++++++++++++Definition des points d'insertion++++++++++++++++
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.Sheets.Item(1)
'Dim oTG As TransientGeometry
'oSheet.Size=9993 A0
'oSheet.Size=9994 A1
'oSheet.Size=9995 A2
'oSheet.Size=9996 A3
'oSheet.Size=9997 A4
'oSheet.Orientation=10243 portrait
'oSheet.Orientation=10242 paysage
'A0portrait
If oSheet.Size = 9993 And oSheet.Orientation = 10243 Then
Xpt3 = oSheet.Width - 9.84
Xpt4 = oSheet.Height - (oSheet.Height - 6.3045)
'A0paysage
ElseIf oSheet.Size = 9993 And oSheet.Orientation = 10242 Then
Xpt3 = oSheet.Width - 9.84
Xpt4 = oSheet.Height - (oSheet.Height - 6.3045)
'A1portrait
ElseIf oSheet.Size = 9994 And oSheet.Orientation = 10243 Then
Xpt3 = oSheet.Width - 9.84
Xpt4 = oSheet.Height - (oSheet.Height - 6.3045)
'A1paysage
ElseIf oSheet.Size = 9994 And oSheet.Orientation = 10242 Then
Xpt3 = oSheet.Width - 9.84
Xpt4 = oSheet.Height - (oSheet.Height - 6.3045)
'A2portrait
ElseIf oSheet.Size = 9995 And oSheet.Orientation = 10243 Then
Xpt3 = oSheet.Width - 8.84
Xpt4 = oSheet.Height - (oSheet.Height - 5.3045)
'A2paysage
ElseIf oSheet.Size = 9995 And oSheet.Orientation = 10242 Then
Xpt3 = oSheet.Width - 8.84
Xpt4 = oSheet.Height - (oSheet.Height - 5.3045)
'A3portrait
ElseIf oSheet.Size = 9996 And oSheet.Orientation = 10243 Then
Xpt3 = oSheet.Width - 8.84
Xpt4 = oSheet.Height - (oSheet.Height - 5.3045)
'A3paysage
ElseIf oSheet.Size = 9996 And oSheet.Orientation = 10242 Then
Xpt3 = oSheet.Width - 8.84
Xpt4 = oSheet.Height - (oSheet.Height - 5.3045)
'A4portrait
ElseIf oSheet.Size = 9997 And oSheet.Orientation = 10243 Then
Xpt3 = oSheet.Width - 8.84
Xpt4 = oSheet.Height - (oSheet.Height - 5.3045)
'A4paysage
ElseIf oSheet.Size = 9997 And oSheet.Orientation = 10242 Then
Xpt3 = oSheet.Width - 8.84
Xpt4 = oSheet.Height - (oSheet.Height - 5.3045)
End If
'++++++++++Definition et insertion de la table de revision+++++++++++++
If oDrawDoc.ActiveSheet.RevisionTables.Count = 0
'Creation du point d'insertion
Dim oPoint2 As Point2d
oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(Xpt3, Xpt4)
'Definition table de revision
Dim oRTBs As RevisionTables
oRTBs = oDrawDoc.ActiveSheet.RevisionTables
'Insertion table de revision
Dim oRTB As RevisionTable
oRTB = oRTBs.Add(oPoint2)
End If
'+++++++++++++Ecriture dans la table de revision+++++++++++++++++
Dim oRevTable As RevisionTable = oDrawDoc.ActiveSheet.RevisionTables.Item(1)
' Choix de la derniere rangee
Dim oRow As RevisionTableRow
oRow = oRevTable.RevisionTableRows.Item(oRevTable.RevisionTableRows.Count)
Dim oCell As RevisionTableCell
'Controle de la presence de donnees dans le reader
If myReader.HasRows = False Then
myReader.Close()
' Verification range active dans tableau
If oRow.IsActiveRow Then
' Go through all columns in that row
For i = 1 To oRevTable.RevisionTableColumns.Count
oCell = oRow.Item(i)
If i = 2 '2nd colonne de la table de revision
oCell.Text = InputBox("Entrer le N° d'OF", "Historique et OF", "XX-XXXXX")
'++++++++++++++++++INSERTION N° DE PLAN DANS BASE SQL++++++++++++++++++++++++++++
Question = MessageBox.Show("VOULEZ VOUS AFFECTER LE N° DE PLAN A L'OF DANS LA BASE SILOG (Ecrire le N° saisi dans la base de données)", "PLAN NON AFFECTE", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Question = vbYes Then
ReqInsert = "UPDATE LCTE Set DesignationLct4 ='" + NumProj + "' Where CodeLancement ='" + oCell.Text + "'"
Dim myCmd2 As New SqlCommand(ReqInsert, myConn)
myCmd2.ExecuteNonQuery()
End If
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ElseIf i = 3 '3eme colonne de la table de revision
oCell.Text = InputBox("Quantité à Produire", "Historique et OF", "1")
ElseIf i = 4 '4eme colonne de la table de revision
oCell.Text = InputBox("Modification", "Historique et OF", "")
End If
oCell.Text = oCell.Text 'defini la cellule en statique
Next
End If
Else
'Inscrire le resultat de la requete dans une chaine de caracteres
myReader.Read()
results = myReader.GetString(0)
' Make sure we have the active row
If oRow.IsActiveRow Then
' Go through all columns in that row
For i = 1 To oRevTable.RevisionTableColumns.Count
oCell = oRow.Item(i)
If i = 2 '2nd colonne de la table de revision
oCell.Text = InputBox("Entrer le N° d'OF", "Historique et OF", results)
ElseIf i = 3 '3eme colonne de la table de revision
oCell.Text = InputBox("Quantité à Produire", "Historique et OF", "1")
ElseIf i = 4 '4eme colonne de la table de revision
oCell.Text = InputBox("Modification", "Historique et OF", "")
End If
oCell.Text = oCell.Text 'defini la cellule en statique
Next
End If
End If
'fermeture du reader et de la connexion
myReader.Close()
myConn.Close()