|
POST
|
Have a look at this older thread: http://forums.esri.com/Thread.asp?c=93&f=992&t=227281 Otherwise, you will have to write your attributes to an ADO.NET DataTable/Dataset then either setup an OleDbDataAdapter to run the updates/inserts to Excel or do this via Excel Automation. Sorry -- I don't have much sample code on this. Good luck!
... View more
05-03-2011
09:51 AM
|
0
|
0
|
907
|
|
POST
|
I am not sure if the ShellExecute function is completed or not, what code needs to be in it, but it is missing an End Function. See:
Private Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
'while the End Function below would get rid of your error
'I don't know what (if anything) code should be in this Function
End Function
... View more
04-29-2011
08:45 AM
|
0
|
0
|
443
|
|
POST
|
First, thanks for your response. That was the way I was leaning too, but i didn't want to have hardcode a connection string. Since the MXD requires certain layers in the TOC I have access to the database, and planned on using the layers connection to gain access to the rest of the database. Hmmm -- there is probably a way to get the name of the server and database from a layer loaded in the TOC. I'd have to dig a bit further into it. You could basically just get those required parameters and still utilize Windows Authentication in the GetConnectionString Function:
Private Function GetConnectionString(ByVal paramServerName, ByVal paramDataBaseName) As String
Return "Data Source=" & paramServerName & ";" _
& "Initial Catalog=" & "paramDataBaseName & "; Integrated Security=True;"
End Function
I want to apologize for this next stupid question up front, but are you able to use the same connection string for an ADODB.Connection as you are for a SqlClient.SqlConnection or a IWorkspace connection? I was under the impression that they were all in different formats and were not interchangable. Don't have a good / direct answer for you here. The SqlClient.SqlConnection is an ADO.NET thing, so my best GUESS would be, no, they're different. But I'd have to dig a bit further to find out for sure.
... View more
04-29-2011
04:53 AM
|
0
|
0
|
983
|
|
POST
|
I have implemented my own DataAccess Layer and classes for the Data-Centric GIS applications I build/maintain. While these are typically N-Tier applications that are also "GIS", I tend to consolodate my db connections (across servers sometimes) into their own classes. Here is an example of a class you could implement that you'd add to your project/assembly (or into another assembly you could reference -- it doesn't really matter).
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class vrConn
Implements IDisposable
Private disposedValue As Boolean = False
Private _LastException As SqlException
Private sqlCn As New SqlConnection()
Public Sub New()
MyBase.New()
Me.openConnection(GetConnectionString)
End Sub
Public Property sqlConn() As SqlConnection
Get
Return sqlCn
End Get
Set(ByVal value As SqlConnection)
sqlCn = value
End Set
End Property
Public Overrides Function ToString() As String
If Me.sqlCn Is Nothing Then
Return ""
Else
Return Me.sqlCn.ToString
End If
End Function
Public Sub openConnection(ByVal cnnString As String)
If sqlCn.State <> ConnectionState.Open Then
Try
If Me.sqlCn Is Nothing Then
Me.sqlCn = New SqlConnection
End If
sqlCn.ConnectionString = cnnString
sqlCn.Open()
Catch sqlEx As SqlException
Me._LastException = sqlEx
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If
End Sub
Public Sub CloseConnection()
If sqlCn.State = ConnectionState.Open Then
sqlCn.Close()
End If
Me.Dispose()
End Sub
Private Function GetConnectionString() As String
Return "Data Source=ServerName;" _
& "Initial Catalog=DataBaseName; Integrated Security=True;"
End Function
Public ReadOnly Property LastException() As SqlException
Get
Return _LastException
End Get
End Property
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
Me.sqlCn = Nothing
GC.Collect()
End If
End If
Me.disposedValue = True
End Sub
#Region " IDisposable Support "
' This code added by Visual Basic to correctly implement the disposable pattern.
Public Sub Dispose() Implements IDisposable.Dispose
' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
End Class
Ok, so once you have this class in your project, you can just reference this and open the connection from whatever other class/form/whatever you are trying to run the StoredProcedure from. This happens to be a "DALC" class (DataAccessLayerClass) I use in one of my assemblies:
Imports System.Data.Sql
Imports System.Data.SqlClient
Private sqlCn As New SqlConnection()
Private connSvc As vrConn
Public Sub New()
MyBase.New()
connSvc = New vrConn
sqlCn = connSvc.sqlConn
End Sub
'Here is a funciton that fills a DataTable of "Species" via a Stored Procedure
Public Function Hydrate_speciesList() As DataTable
Dim spCmdSpec As SqlCommand = New SqlCommand()
spCmdSpec.CommandText = "dbo.SpeciesSelect"
spCmdSpec.CommandType = CommandType.StoredProcedure
Dim ds As New DataSet()
Dim da As New SqlDataAdapter
Try
Me.OpenConnection()
Using spCmdSpec
spCmdSpec.Connection = Me.sqlCn
da.SelectCommand = spCmdSpec
da.Fill(ds, "species")
End Using
Me.CloseConnection()
Dim tb As DataTable = ds.Tables("species")
tb.Rows.RemoveAt(0)
Return tb
Catch ex As Exception
MsgBox(ex.ToString)
Me.CloseConnection()
Return Nothing
End Try
End Function
'database connectivity
Private Sub CloseConnection()
If sqlCn.State = ConnectionState.Open Then
sqlCn.Close()
End If
End Sub
Private Sub OpenConnection()
If sqlCn.State = ConnectionState.Closed Then
sqlCn.Open()
End If
End Sub
... View more
04-28-2011
03:05 PM
|
0
|
0
|
983
|
|
POST
|
One solution (just a first thought) is to add and populate another field (say you call it "Exercised") similar to the way I have implemented a "FlagType". Basically, you'd populate this field with values that can only be one of two things (strings): Exercised>5yrs, Exercised<5yrs This would occur before any rendering would happen, so that when you do get to your rendering you could set your queryFilter to either of these strings and the renderer to this field as well: uvRenderer.AddValue(feature.Value(feature.Fields.FindField("Exercised")), "", sym) Hope this is clear and was just a quick thought. james
... View more
04-27-2011
05:58 PM
|
0
|
0
|
1216
|
|
POST
|
Thanks jamesfreddyc, your solution almost worked... The only issue with it is that it creates a symbol for each unique date which looks rather ugly in the TOC. Ultimately there should only be two symbols in the TOC; one for old features (> than 5 years old) and one for new features (<= 5 years old). Is it still possible to achieve this using a UniqueValueRenderer? huh. The code I provided does exactly that for me --- it symbolizes the point layer with ONLY 2 specific symbols that is based upon the values found in "FlagType". So if FlagType = 'x', then the point symbols were size 4 and if FlagType = 'Y' then the point symbols were size 8 (of course that's just a generalization). Maybe the problem lies in the WHERE clause? Not sure. What exactly are you seeing for symbols? And lets see the code you are using (we might be able to help you alter it a bit to accomplish what you want).
... View more
04-27-2011
01:11 PM
|
0
|
0
|
1216
|
|
POST
|
It depends on what you're using to create your installer. Using the standard Visual Studio deployment project you just open the File System view and add the file to the correct folder. You can create a registry entry on the Registry view and set its value using [TARGETDIR] plus the rest of the path to the database (i.e. [TARGETDIR]\Data\ourDatabase.mdb). Yep. That's it! Much appreciated!
... View more
04-27-2011
12:34 PM
|
0
|
0
|
668
|
|
POST
|
Neil, Thanks a bunch for the input. I think I am heading down the right path here, but could you clarify how you include the PGDB in the .msi package? That is, do I just add the PGDB (.mdb) file to the Project? How do I tell it where to install/place this file? Also, this: WeThe only thing that changes is the root directory where the user chooses to install the application. You can also just have the installer create a registry entry that contains the path to the database and have your code read the path from that registry key. Do you have an example or walkthru on how to accomplish this? How Thank You!!!
... View more
04-27-2011
12:09 PM
|
0
|
0
|
668
|
|
POST
|
Thanks for trying to help. The form I am trying to open was created in the VBA of the MXD. So this form is not include with the VB.Net project. For some reason ESRI did not see it fit to have my button controls to come in like they have from all other version jumps where VBA is allowed. So my project does this: 1.) Create an add-in button in VB.Net that opens my form that is in the MXD and not the .net solution. Hopefully that makes some sense. Please tell me I can do this. Recreating these forms in .net is going to take forever. I have decades of code in VBA. ouch. Well, hopefully someone will jump in here and provide a solution. That's a lot of VBA code. Have you considered moving competely out of VBA/Add-in model and convert everything over to your own .NET assemblies? Yes, it would be painful (it was to me too), but you will free yourself from the conditions/confines that you are finding yourself in now and in the future. VBA is totally gone at ArcGIS v10.1 I think. And yes, I find that the initial attempts at deployment/distribution is a pain, but it does get better as you gain experience when things go bad. That is if deployment issues are what caused you to stick with VBA.
... View more
04-27-2011
12:04 PM
|
0
|
0
|
771
|
|
POST
|
Is there a specific method or process to distribute a Personal Geodatabase with a Setup.exe or Installer.msi? I'd like to distribute a PGDB that my extension uses with the .msi that is built for deploying the assembly. Are there any specific suggestions on AppPath settings? For example, I have some code that opens an IFeatureWorkspace of that PGDB: pWorkspaceFactory.OpenFromFile(db_path & "\Reporting.mdb", 0) I guess my question on AppPath would be where exactly would the Installer set AppPath? Edit: here is my current GetAppPath function:
Private Shared Function GetAppPath() As String
Dim path As String
path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location)
Return path
End Function
... View more
04-27-2011
11:33 AM
|
0
|
4
|
1205
|
|
POST
|
I am really in the unknown class when it comes to these Add-in things, but I can comment on opening Userforms.... So, let's say I have a button on a toolbar that needs to open a WindowsForm that I have added to my project/assembly. Let's call it "frmMain". So, in my class that has the Button's Click event, I would state what the frmMain is:
Private m_frmMain As frmMain
Then in the Button_Click, I'd create a new frmMain and show it:
If Not m_frmMain Is Nothing Then
m_frmMain.Dispose()
m_frmMain = Nothing
m_frmMain = New frmMain
m_frmMain.Show()
Else
m_frmMain = New frmMain
m_frmMain.Show()
End If
... View more
04-27-2011
11:16 AM
|
0
|
0
|
771
|
|
POST
|
I tried placing the stop at several different points in the function, but regardless I get this error in the Immediate Window: A first chance exception of type 'System.InvalidCastException' occurred in PrecinctSearch2.dll
A first chance exception of type 'System.InvalidCastException' occurred in PrecinctSearch2.dll
A first chance exception of type 'System.InvalidCastException' occurred in PrecinctSearch2.dll It seems vague, but I am trying to research what may be causing this. Is PrecinctSearch included as a reference in your assembly/project? Is PrecinctSearch an assembly you have built? j
... View more
04-27-2011
10:16 AM
|
0
|
0
|
1831
|
|
POST
|
Unfortunately, when I attempt to "Step Into" the function, it just launches ArcMap and goes into debug mode. The "Step Into" and "Step Over" tools become greyed out so I can't even diagnose where the exception is occuring. Actually, that's what I meant: step thru in debug mode by putting a stop somewhere. You can hit F11 to move to the next line, F5 will continue with the full execution. Edit: also, Debugging means that it launches ArcMap. This is expected.
... View more
04-27-2011
09:01 AM
|
0
|
0
|
1831
|
|
POST
|
Thanks, James. I am still getting the fatal exception when I try to run the program, but adding the single quotes to the where clause is still a good idea. Maybe the exception is coming from somewhere else in your application/code. I really don't know. You can: 1. Put a stop somewhere in that particular funciton and step thru the code line by line and see where it fails. 2. This is a good idea to do anyway: put in a Try Catch block to trap and show error messages. Try
'some code that does stuff here
Catch ex As Exception
MsgBox(ex.ToString)
End Try
... View more
04-27-2011
08:32 AM
|
0
|
0
|
1831
|
|
POST
|
I don't know if this is the ONLY problem/cause of your issue, but when querying String/Text type fields, you need to put the WHERE clause in single quotes. Something like this (I am writting this in VB.net so not sure if replacing "+" with "&" as I have done will affect it):
whereClause = "PRECINCT = '" & txtPrecinctSearch.Text & "'"
james I'm still having difficulty with this. The links provided are a very high-level overview, but I can't seem to find a way to get started. I have got my button click function this far: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pMap As IMapDocument
Dim activeView As IActiveView
Dim featureLayer As IFeatureLayer
Dim whereClause As String
pMap = New MapDocument
activeView = pMap
featureLayer = pMap.Layer(0, 0)
whereClause = "PRECINCT = " + txtPrecinctSearch.Text
SelectMapFeaturesByAttributeQuery(activeView, featureLayer, whereClause)
End Sub The variable txtPrecinctSearch.Text is coming from a user input textbox on the form. There are no errors shown in the code, but I get a fatal exception when I try to run this. I just don't understand what is causing the problem. It really is ridiculous that there is no clear documentation on how to set up the variables for the current map, active map frame, and the selected layer.
... View more
04-27-2011
08:14 AM
|
0
|
0
|
1831
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|