I hope you can Help, I have done a Lot of SLX Bespoke but this is the First external VB.NET app I have done.
I have Started with Ryans Tuts and got My Base Class (Class1) and this then opens my form passing an ACCOUNTID and then populating an Editable Grid View with all the contacts from the ACCOUNT, this works fine.
This allows the user to edit, add contacts in a spreadsheets fashion and then update all with a single click.
The problem I am having is that all my SLX references work fine in the base class (Class1) but I get the dredded "Object reference not set to an instance of an object" when running them from my (Form1) class.
I have tried with the Function in the Class1 and in the Form1 class to no avail.
My knowledge of VB.NET is quite new so please excuse the simplicity of the code.
I create a new instance of the Class1 (Class3) in my Form1 class but still get the error.
<p>Imports System.Data.OleDb
Imports Sage.SalesLogix.NetExtensions
Imports Sage.SalesLogix.NetExtensions.BaseRunnable
Public Class Class1
Inherits Sage.SalesLogix.NetExtensions.BaseRunnable
Public FormGrid As New Form1
Public Overrides Function Run(ByVal Args() As Object) As Object
Dim msg As String = "Hello .NET-SalesLogix World!" & vbCrLf & vbCrLf & _
"Argument passed: " & IIf(Args.Length = 0, "None", Args(0)) & vbCrLf & _
"Current userid: " & SlxApplication.BasicFunctions.CurrentUserID() & vbCrLf & _
"Current Accountid: " & SlxApplication.BasicFunctions.CurrentAccountID & vbCrLf & _
"Connection String: " & SlxApplication.ConnectionString
Call ShowForm()
Return Nothing
End Function
Public Sub ShowForm()
Dim connection As OleDbConnection
Dim oledbAdapter As OleDbDataAdapter
Dim ds As New DataSet
Dim sql As String
sql = "SELECT CONTACTID, FIRSTNAME, LASTNAME, TITLE, WORKPHONE, EMAIL, AFPTIS_STATUS, ISPRIMARY FROM sysdba.CONTACT WHERE ACCOUNTID = '" & SlxApplication.BasicFunctions.CurrentAccountID & "'"
connection = New OleDbConnection(SlxApplication.ConnectionString)
FormGrid.SLXConnection = SlxApplication.ConnectionString
FormGrid.SLXAccountID = SlxApplication.BasicFunctions.CurrentAccountID
FormGrid.Show()
Try
connection.Open()
oledbAdapter = New OleDbDataAdapter(sql, connection)
oledbAdapter.Fill(ds)
oledbAdapter.Dispose()
connection.Close()
FormGrid.DataGridView1.AutoGenerateColumns = True
FormGrid.DataGridView1.DataSource = ds.Tables(0)
FormGrid.DataGridView1.Columns(0).Visible = True
FormGrid.DataGridView1.Refresh()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
<p>Imports System.Windows.Forms
Imports System.Data.OleDb
Imports Sage.SalesLogix.NetExtensions
Imports Sage.SalesLogix.NetExtensions.BaseRunnable
Public Class Form1
Public SLXConnection As String
Public SLXAccountID As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connection As OleDbConnection
Dim oledbAdapter As OleDbDataAdapter
Dim ds As New DataSet
Dim sql As String
Dim RowCount As Integer
RowCount = DataGridView1.RowCount - 2
connection = New OleDbConnection(SLXConnection)
Call GetNewIDforContact()
Try
connection.Open()
For i = 0 To RowCount
sql = "UPDATE sysdba.CONTACT SET AFPTIS_STATUS = '" & Trim(DataGridView1.Item(6, i).Value.ToString) & _
"' , FIRSTNAME = '" & Trim(DataGridView1.Item(1, i).Value.ToString) & "' , LASTNAME = '" & Trim(DataGridView1.Item(2, i).Value.ToString) & _
"' , TITLE = '" & Trim(DataGridView1.Item(3, i).Value.ToString) & "' , WORKPHONE = '" & Trim(DataGridView1.Item(4, i).Value.ToString) & _
"' , EMAIL = '" & Trim(DataGridView1.Item(5, i).Value.ToString) & "' , ISPRIMARY = '" & Trim(DataGridView1.Item(7, i).Value.ToString) & _
"' WHERE CONTACTID = '" & Trim(DataGridView1.Item(0, i).Value.ToString) & "'"
oledbAdapter = New OleDbDataAdapter(sql, connection)
oledbAdapter.Fill(ds)
oledbAdapter.Dispose()
Next
MessageBox.Show("Finished", "Finished")
connection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Function GetNewIDforContact()
Dim Class3 As New Class1
Dim ContactID As String
MsgBox("I am Here")
ContactID = Class3.SlxApplication.BasicFunctions.GetIDFor("contact")
MsgBox(ContactID)
Return ContactID
End Function
End Class