Connection sql in iLogic

Connection sql in iLogic

Anonymous
Not applicable
1,730 Views
3 Replies
Message 1 of 4

Connection sql in iLogic

Anonymous
Not applicable

Hi!,

I need to connect in sql server, in iLogic for make a insert in a database.

But when I try , the error raise : ADODB.Connection is not define.
I write this before : 

AddReference "System.Data"
AddReference "System.Core"
AddReference "System.Xml"
Imports System.Data.OleDb
Imports System.Data
Imports System.Xml
What I'm missing, do I import a library ?

If yes, which ?

0 Likes
Accepted solutions (1)
1,731 Views
3 Replies
Replies (3)
Message 2 of 4

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

I assume you connect with something like:

Dim ADOCon As New ADODB.Connection

This is for VB6 and earlier afaik.

Try using instead somthing like:

    Public Sub ConnectToSql()
        Dim conn As New SqlClient.SqlConnection
        ' TODO: Modify the connection string and include any
        ' additional required properties for your database.
        conn.ConnectionString = "integrated security=SSPI;data source=SQL Server Name;" _
        "persist security info=False;initial catalog=northwind"
        Try
            conn.Open()
            ' Insert code to process data.
        Catch ex As Exception
            MessageBox.Show("Failed to connect to data source")
        Finally
            conn.Close()
        End Try
    End Sub

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 4

ashish.patilSP94R
Participant
Participant

HOW TO USE SQL QUERY IN INVENTOR 

CAN YOU PLZ HELP ME IN THIS

0 Likes
Message 4 of 4

Ralf_Krieg
Advisor
Advisor

Hello

 

Here's an more detailed example. You need to edit the connection settings and the sql string.

Can you explain more in detail what you want to do?

 

 

AddReference "System.Data.dll"
Imports System.Data.SqlClient

Sub main
	'ENTER your connection settings here
	Dim sConn As String = String.Empty
	sConn="server=$SERVERADDRESS;uid=$USERNAME;pwd=$PASSWORD;database=$DATABASENAME" 
	
	'Enter Tablename and values to insert
	'If there are less values than columns in your table, you need to specify wich value corresponds to which column
	Dim sql As String = String.Empty
	sql = "Insert into $TABLENAME values('" & strValue1 & "','" & strValue2 & "','" & strValue3 & "','" & strValue4 & "')"
	
	If ExtSql(sConn, sql) Then
		MsgBox("Command executed", MsgBoxStyle.Information, "iLogic")
	End If
End Sub


Function ExtSql(ByVal sConn As String, ByVal sql As String) As Boolean
    Dim cnn As SqlConnection
    Dim cmd As SqlCommand
    cnn = New SqlConnection(sConn)
    Try
        cnn.Open()
        cmd = New SqlCommand
        cmd.Connection = cnn
        cmd.CommandType = System.Data.CommandType.Text
        cmd.CommandText = sql
        cmd.ExecuteNonQuery()
        cnn.Close()
        cmd.Dispose()
    Catch ex As Exception
        cnn.Close()
        Return False
    End Try
    Return True
End Function

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes