|
Hello !
Is it possible to separate each project's form in different dll files , and to call them when needed ?
To be more clear , currently when the project is compiled , an .exe file is created and all the code related to different forms are inside the .exe.
Is it possible to change this behavior , so on exe to have only the main's form code , that just call other forms from dll files ?
Thank you !
|
|
|
|
|
Yes it is but at a cost of increased complexity.
You'd have to create a class library project for each of your forms. The class files in those projects should be changed immediately to inherit from System.Windows.Forms.Form. It's then possible to open them up in the designer and drop controls on them.
You're also going to have to change the InitializeComponent() method in each of those forms from "private" to "public" so you can call it from the calling form. This will setup the controls on the new form so that they are visible.
You then have to go back the project that's going to use this form and add a project reference to each of the forms that this form is going to use. You then can create a new instance of the form but you're going to have to initialize it yourself, something like this:
using (var newForm = new Form2.Form2())
{
form2.InitializeComponent();
form2.ShowDialog();
}
I don't see any benefit that outways the complexity of doing this, so what's the point?
|
|
|
|
|
I have some reasons , but maybe I'm wrong , so I need an opinion :
1) Different people take care programming of different forms
2) Some time 1 clients want some changes in one or same forms that don't affect the remaining forms. So they can be prepared as dll's and installed to only these clients.
3)The project use a database. In general the database is the same for all clients. But sometimes some clients ask for changes on database that affect the controls in one or some forms. But not all clients wants this. So we can prepare the corresponding database and dll's for these clients only and installed to them.
4) The forms contains some Entity framework queries , that may be different for different clients.
|
|
|
|
|
Separating this stuff into their own projects may work, but as I said before, it just adds complexity to your project structure and makes it ridiculously easy to ship the wrong .DLL's to the right customer.
What solves these problems is version control, like Git, SVN or TFS. Branching of the source lets you create multiple custom versions of the source code that can share code as well as isolate each branch from the others so you don't end up shipping the wrong executables to the customers.
|
|
|
|
|
Dave Kreskowiak wrote: I don't see any benefit that outways the complexity of doing this, so what's the point? I've seen the discussion in the Lounge.
Modularity comes to mind; if the interface to show the form does not change, one can easily update the dll without touching the executable. Doesn't mean that you should go ahead and put every class in a separate dll without thinking - that way the added complexity becomes unmanagable, without providing any benefits at all.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you !
But each form has a specific purpose.
And in general the forms for different clients are similar.
But for example :
One client need some extra fields in database , and of course need some extra controls on the form , some modifications to Entity framework queries , some extra/less columns in a datagridview...etc. But of course that I don't know this on the beginning , the client may ask for these modifications time to time , so I need way to update different clients with different modifications that they ask.
So in this case , I think to use separate dll for each form class.
If someone knows a link where I can see a simple project that use this idea , would be helpful , or this is not a good idea , and someone knows a better solution ?
|
|
|
|
|
Any example that shows how to create a separate project, add a reference, and invoke a form would do.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I wrote a program that is now in use by quite a few friends and over the past few years, I've updated the program with additional field added to tables I need to develop a program that will make these change without me going to them and doing this in person. Can some one help me.
|
|
|
|
|
How can we help?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Well, you haven't said anything about what you need help with, so I'll give you a large hint.
All SQL database engines are manageable by executing SQL statements against them. That includes security, adding/deleting indexes, tables, columns, and obviously rows.
So, you just come up with the SQL statements to make the required changes to your tables/columns/rows and execute those against the database.
|
|
|
|
|
Imports System.Data.OleDb
..
Dim provider As String
Dim dataFile As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
provider = Microsoft.ACE.OLEDB.4.0;Data Source = "
dataFile = "C:\DBtest\test.mdb"
connString = provider + dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String = "ALTER TABLE Items ADD COLUMN Rhour MONEY"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
myConnection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
|
|
|
|
|
I have just written a very simple app that displays a form with a single ShockWave Flash control. It runs fine under VS and as a standalone EXE on my development machine (Windows 10 Pro). But when I copy the EXE, associated DLLs, and SWF files to a Windows 7 Pro machine and run it, all I get is a totally white frame. What else do I need to do on the customer machine to make it run?
|
|
|
|
|
Install Flash.
It's bad idea to make an application that's reliant on Flash because the industry is trying to kill it off. It's probably the most insecure piece of software in existence right now.
modified 1-Jun-16 18:00pm.
|
|
|
|
|
Hello geeks
My struggle with Updating data seems never ending. My latest code is as below:
Private Sub StaffInfoAdapterUpdate(ByVal conxnString As String)
Dim cmdText As String
cmdText = "SELECT StaffID, StaffName, blCampuses.CampusName,
Designation, DOB, Gender, NIC, DateOfJoining
FROM tblStaffInfo
INNER JOIN tblCampuses
ON tblStaffInfo.CampusID = tblCampuses.CampusID"
Using Conxn As SqlConnection = New SqlConnection(conxnString)
Dim adapter As SqlDataAdapter = New SqlDataAdapter(cmdText, Conxn)
Dim strUpdate As String = "UPDATE StaffName
SET StaffName = @StaffName " & "WHERE StaffID = @StaffID"
adapter.UpdateCommand = New SqlCommand(strUpdate, Conxn)
adapter.UpdateCommand.Parameters.Add("@StaffName", SqlDbType.VarChar, 50, "StaffName")
Dim parameter As SqlParameter =
adapter.UpdateCommand.Parameters.Add("@StaffID", SqlDbType.Int)
parameter.SourceColumn = "StaffID"
parameter.SourceVersion = DataRowVersion.Original
Dim StaffInfoTable As New DataTable
Try
adapter.Fill(StaffInfoTable)
adapter.Update(StaffInfoTable)
Catch ex As Exception
MsgBox("Error: " & ex.Message)
End Try
End Using
End Sub
When I modify the StaffName for testing, the code does not throw any error, but does not update the record either.
Please note that StaffID is the Primary Key of tblStaffInfo
Please help!
I have a point to clarify in this respect:
Do I have to include ALL the Fields in the strUpdate; which are included in cmdText string; even if most of the fields are least expected to be modified?
|
|
|
|
|
Raabi Anony wrote: Dim StaffInfoTable As New DataTable
Try
adapter.Fill(StaffInfoTable)
adapter.Update(StaffInfoTable)
You create a new DataTable , load the data from the database, and then update the database with the data you've just loaded. There's nothing in that code that changes the data.
Are you missing part of your code from the question?
Raabi Anony wrote: Do I have to include ALL the Fields in the strUpdate; which are included in cmdText string; even if most of the fields are least expected to be modified?
You have to include all of the fields you want to update, along with the primary key. If a field isn't going to be updated, and it's not the primary key, then you don't need to include it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Homer, for your attention. I am reading the data in datagridView and modify it there only.
Do I need to make changes for this scenario? Please suggest!
Regards
|
|
|
|
|
The code you've posted isn't touching your DataGridView . You load the data from the database, and then immediately update the database with the data you've just loaded.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, Richard, for your attention and sorry for leaving out a change in the code, for the test purpose, as below:
Dim strUpdate As String = "UPDATE StaffName SET StaffName = 'Anonymous'" & "WHERE StaffID = 1005"
A record with the StaffID = 1005 exists.
But the record doesn't get changed, as expected (by me ). What mistake I am doing.
Please suggest.
I have tried the following code, as well:
Private Sub StaffInfoAdapterUpdate()
Dim ConxnString As String = "Data Source=Dar-e-Arqam\SQLEXPRESS; Initial Catalog=StaffReport;
Integrated Security=True"
Dim Conxn As New SqlConnection(ConxnString)
Dim cmd As SqlCommand = Conxn.CreateCommand()
Dim StaffInfoDS As New DataSet()
Dim StaffInfoAdapter As New SqlDataAdapter()
Dim cmdText As String = "SELECT StaffID, StaffName, tblCampuses.CampusName, Designation,
DOB, Gender, NIC, DateOfJoining
FROM tblStaffInfo
INNER JOIN tblCampuses
ON tblStaffInfo.CampusID = tblCampuses.CampusID"
Dim strUpdate As String = "UPDATE StaffName " &
"SET StaffName = 'Anonymous' " & "WHERE StaffID = 1005"
Try
Conxn.Open()
cmd.CommandText = strUpdate
cmd.ExecuteNonQuery()
MsgBox("The record updated. Really?")
Catch ex As Exception
MsgBox("Error: " & ex.Message)
End Try
End Sub
The above code throws an error: "Invalide object name 'StaffName'.
I am very disturbed for this problem.
Please help.
modified 2-Jun-16 23:26pm.
|
|
|
|
|
Your table is called tblStaffInfo, so your update statement needs to be
Raabi Anony wrote: Dim strUpdate As String = "UPDATE tblStaffInfo " &
"SET StaffName = 'Anonymous' " & "WHERE StaffID = 1005"
Try
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Wow, such a major mistake, I had been overlooking.
Thanks Chris Quinn and keep your glass always FULL
|
|
|
|
|
Hello everybody
My following code seems very non-cooperative and issues the error: Dynamic SQL generation is not supported against multiple base tables
Dim conxnString As String = "Data Source=Raabi\SQLEXPRESS; Initial Catalog=StaffReport; Integrated Security=True"
Dim conxn As New SqlConnection(conxnString)
Dim cmd As SqlCommand = conxn.CreateCommand()
Dim StaffInfoDS As New DataSet()
Dim StaffInfoAdapter As New SqlDataAdapter()
Dim StaffInfoTbl As DataTable
Private Sub PopulateStaffInfoDGV()
Dim cmdText As String
cmdText = "SELECT StaffID, StaffName, tblCampuses.CampusName, Designation, DOB, Gender, NIC, DateOfJoining
FROM tblStaffInfo
INNER JOIN tblCampuses
ON tblStaffInfo.CampusID = tblCampuses.CampusID"
Try
cmd.CommandText = cmdText
StaffInfoAdapter.SelectCommand = cmd
conxn.Open()
StaffInfoAdapter.Fill(StaffInfoDS, "StaffInfoTbl")
StaffInfoDGV.DataSource = StaffInfoTbl
conxn.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Message)
End Try
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim cmdbldr As New SqlCommandBuilder(StaffInfoAdapter)
cmdbldr.GetUpdateCommand()
StaffInfoAdapter.Update(StaffInfoDS, "StaffInfoTbl")
End Sub
Any help is highly appreciated.
|
|
|
|
|
According to SqlCommandBuilder Class (System.Data.SqlClient)[^]
Quote: Automatically generates single-table commands that are used to reconcile changes made to a DataSet with the associated SQL Server database. This class cannot be inherited.
The key word here is "single-table".
You have to use the appropriate InsertCommand, UpdateCommand, or DeleteCommand to do the job as shown in Updating Data Sources with DataAdapters[^]
Peter Leow
https://www.amazon.com/author/peterleow
modified 30-May-16 0:24am.
|
|
|
|
|
Thanks, Peter, for the attention.
Let me try the stuff at the link, provided by you. I may get back, if further guidance is needed.
Regards
|
|
|
|
|
As the error states you cannot update the 2 tables via a dataadaptor. The inner join is getting data from 2 table and presenting it to you UI.
You need to only update the tblStaffInfo as the campus name is there for display purposes only. I used to do the following:
get an empty datatable record by passing in Select * from tblStaffInfo where 1=-1
Add a record to the enpty datatable
populate it with the updated content from your joined datatable
pass the new record to the dtataadaptor to do the update.
Clumsy and ugly but it gets the job done. This is a learning process for you and will be invaluable in the future giving you a grounding in database manipulation.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank, RAH, for hinting towards a new direction for solution.
I will try to implement the idea. Unfortunately, I am almost a novice in databases and therefore I have to struggle a lot in order to grasp the hints.
I will appreciate, if you could emphasize a bit more on your point.
Regards
|
|
|
|