Jump to content
Xtreme .Net Talk

benpaul

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by benpaul

  1. Hi All! I have a query regarding the best practice when working with data driven MDI children... lets say that the user had a number of windows open, within one of these open windows I have a 'Receipts Total' text box which will give the total amount of all receipts held in the database. Now, from another MDI Child, the user selects a button which opens a window allowing them to add a new receipt to the system, this is simply a form and a save button... when the save button is clicked, a message box informs them that the new receipt is saved and the add receipt window is closed. My problem is that all MDI children will now need to be closed and reopened by the user for the totals etc to be updated... how I would I go about triggering a 'refresh'n of all the MDI children to make sure that when a receipt is saved, the new values are reflected across the application? Many Thanks in Advance!! Ben
  2. I think the issue is that .NET centres the window to the MDI parent based on the 'size' values that you set for the MDIParent properties. When you maximise the MDIParent, the 'size' values do not change, therefore 'CenterParent' will not give the desired result. I have always used CenterScreen with no problems so far. Sub CenterInParent(ByVal parent As Form, ByVal child As Form) Dim frmA As Form = parent Dim frmB As Form = child Dim x As Integer = (parent.Width / 2) - (child.Width / 2) Dim y As Integer = (parent.Height / 2.2) - (child.Height / 2) child.Location = New Point(x, y) End Sub This will also solve the problem, and will always find the middle of the Parent in its current state (maximised or not).
  3. I have solved this, it seems that this was always working. What actually happens is that becuase I chose to export the database with each build, when i choose to debug the app, it creates a build and copies in a database that overwrites the copy of the database that the previous build had created... overwriting the changes. This does make debugging quite difficult for me, however now at least I can be sure of my code.
  4. Hi All, I have the following code.... private void button2_Click(object sender, EventArgs e) { decimal myAmount = System.Convert.ToDecimal(this.amountTextBox.Text); decimal myVat = System.Convert.ToDecimal(this.vatTextBox.Text); int mySupplier = System.Convert.ToInt32(this.supplierComboBox.SelectedValue); string myDescription = this.descriptionTextBox.Text; DateTime myDateAdded = DateTime.Parse(this.dateaddedDateTimePicker.Text); int myEventID = iPromote.eventID; int mySupplierID = System.Convert.ToInt32(this.supplierComboBox.SelectedValue); try { this.receiptsTableAdapter1.Insert(myAmount, myDescription, myVat, myDateAdded, myEventID, mySupplierID); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } It is basically, taking the values from my various text boxes on the form and trying to insert a new record in the database using those values... This is creating no exceptions or any errors, however when I close the app and check the database, the table in the database doesnt contain any of the information i had hoped to write to it.... Can anyone spot any problems with the code? I am very new to .NET!
  5. Hi All, Sorry, I have checked as many forums as I can and also googled etc, but to be honest I dont really know what im looking for! My problem is this... I have an application, when it first starts it displays a windows form that has a combobox populated with a list of 'events' that the user has created... this is working correctly... the user selects the 'event' that they want to administrate and this sets a variable that is available throughout the app (the EVENT ID). now... when they click the 'select' button, it closes this first form (after setting my eventID variable) and then displays another form that I will use to display a listbox of all the records in an SQL COMPACT database table that has an 'eventid' that matches the one we set from the first forums COMBOBOX. Anyways... what I effectivly want to do is populate a listbox using an SQL SELECT query a little like the one below... string SqlQuery = "SELECT * FROM receipts WHERE eventid="+eventID; I am sorry if this seems like a very mundane question, I just cant find the answer anywhere... any help would be much appreciated.
  6. Fantastic, thankyou very much for your excellent help! I kind of grasped that it would be best to have a higher level class that dealt with things like creating a connection etc, if nothing else to stop replication of code each time I want to retreive data, your links have provided a good source for me to read from in order to get closer to that. Many Thanks!
  7. Hi All, Brand new to the forum, I have been reading for a short while and have found lots of intresting threads that have helped me begin with .NET and specifically (C#) so thanks for that! Anyways, here is what I have been up to while learning... I am writing a windows forms application that utilizes an SQL SERVER EXPRESS database to store and retreive data. What I would like your views on really, are the best practices when retreiving data from the database... at the moment I have a class which basically contains a set of methods that I use to retreive different bits of data from my database... for example... private string connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString; public decimal getReceiptsTotal(int eventID) { string source = connectionString; string select = "SELECT amount FROM receipts WHERE eventid="+ eventID; SqlConnection conn = new SqlConnection(source); conn.Open(); SqlCommand cmd = new SqlCommand(select, conn); SqlDataReader reader = cmd.ExecuteReader(); decimal total = 0.00m; while (reader.Read()) { total = total + (decimal)reader[0]; } conn.Close(); return total; In the above code, I have a table called 'Receipts' which contains an eventid and an amount... what it does is grab all of the receipts for that event in the database and adds them together, finally returning the result. (Im sure its not amazingly pretty code but it works). Now.... this class holds lots of similar methods that return various bits of data from the database, not all of them decimals... I have a function that returns the event name for example, as a string. Obviously, each time a method is called... it creates a new connection to the database, sends the SELECT statement, grabs the result and returns it... is this good practice? Creating a connection to the database in the above way everytime I want some data from the database? it seems logical to me to do it this way, mainly becuase it works I guess... but just wanted to get some views on how others would do the same transactions. This line... private string connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString; This is grabbing my connection string from the app Configuration, and is accessable by the whole class so each method just calls the variable 'connectionString' when it needs to create the connection, I dont declare this more than once in the whole app. I hope this is clear to you all, and I look forward to your replys! Thanks in advance! Ben
×
×
  • Create New...