473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Adding new row to table from form.

Good afternoon All I have got over some hurdles on my current project and now I am stuck again.

Im now having issues with writing the code that takes the calculations from my txt boxes and inserts them as a new row in my access database.

I used the Visual Studio 2005 Wizard to create my DB connections, so im struggling to work it all out.

Here is the code for my form:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4.  
  5. Public Class frmCalculator
  6.  
  7.     Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
  8.  
  9.         'ends application
  10.         Me.Close()
  11.  
  12.     End Sub
  13.  
  14.     Private Sub TblPurchaseBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  15.         Me.Validate()
  16.         Me.TblPurchaseBindingSource.EndEdit()
  17.         Me.TblPurchaseTableAdapter.Update(Me.DsLeopard.tblPurchase)
  18.  
  19.     End Sub
  20.  
  21.     Private Sub frmCalculator_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  22.  
  23.         'have the user confirm that they want to exitt he application
  24.         e.Cancel = (MessageBox.Show("Are you sure you want to exit?", "Closing Application", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No)
  25.  
  26.     End Sub
  27.  
  28.     Private Sub frmCalculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  29.  
  30.         'fills the dataset for the tblProducts with Data
  31.         Me.TblProductsTableAdapter.Fill(Me.DsLeopard.tblProducts)
  32.  
  33.         'fills the dataset for the tblPurchase with data
  34.         Me.TblPurchaseTableAdapter.Fill(Me.DsLeopard.tblPurchase)
  35.  
  36.  
  37.         lblProductIDCombo.Visible = False
  38.         cmbProductID.Visible = False
  39.  
  40.     End Sub
  41.  
  42.  
  43.     Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
  44.  
  45.         'calls the PrintForm method
  46.         PrintForm()
  47.  
  48.     End Sub
  49.  
  50.     Public Sub PrintForm()
  51.         ' Takes a screenshot, then initiates the print
  52.         GrabScreen()
  53.         myPrintDialog.Document = myPrintDocument
  54.         If myPrintDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
  55.             myPrintDocument.Print()
  56.         End If
  57.     End Sub
  58.  
  59.     ' API call to help generate final screenshot
  60.     Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal _
  61.         hdcDest As IntPtr, ByVal _
  62.         nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth _
  63.         As Integer, ByVal nHeight _
  64.         As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc _
  65.         As Integer, _
  66.         ByVal nYSrc As Integer, ByVal dwRop As System.Int32) _
  67.         As Boolean
  68.     ' Variable to store screenshot
  69.     Private bmpScreenshot As Bitmap
  70.  
  71.     Private Sub GrabScreen()
  72.         ' Performs a screenshot, saving results to bmpScreenshot
  73.         Dim objGraphics As Graphics = Me.CreateGraphics
  74.         Dim objSize As Size = Me.Size
  75.         Const SRCCOPY As Integer = &HCC0020
  76.  
  77.         bmpScreenshot = New Bitmap(objSize.Width, objSize.Height, _
  78.                                    objGraphics)
  79.         Dim objGraphics2 As Graphics = _
  80.             Graphics.FromImage(bmpScreenshot)
  81.         Dim deviceContext1 As IntPtr = objGraphics.GetHdc
  82.         Dim deviceContext2 As IntPtr = objGraphics2.GetHdc
  83.  
  84.         BitBlt(deviceContext2, 0, 0, Me.ClientRectangle.Width, _
  85.           Me.ClientRectangle.Height, deviceContext1, 0, 0, SRCCOPY)
  86.         objGraphics.ReleaseHdc(deviceContext1)
  87.         objGraphics2.ReleaseHdc(deviceContext2)
  88.     End Sub
  89.  
  90.     Private Sub myPrintDocument_PrintPage(ByVal sender _
  91.       As System.Object, _
  92.       ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
  93.       Handles myPrintDocument.PrintPage
  94.         ' Method that handles the printing
  95.         Dim objImageToPrint As Graphics = e.Graphics
  96.         objImageToPrint.DrawImage(bmpScreenshot, 0, 0)
  97.         bmpScreenshot.Dispose()
  98.         objImageToPrint.Dispose()
  99.         e.HasMorePages = False
  100.     End Sub
  101.  
  102.     Private Sub Compute()
  103.  
  104.         'This Sub Procedure calculates the Shipping, tax and Total Cost
  105.  
  106.         prodPrice = txtProdPrice.Text
  107.         prodQuantity = txtOrderQuant.Text
  108.  
  109.         'Total price of items, minus tax and shipping
  110.         totalPrice = prodPrice * prodQuantity
  111.  
  112.         'Calculates the shipping cost
  113.         shipCost = totalPrice * 0.1
  114.         'Displays Shipping cost in text box
  115.         txtShipCost.Text = shipCost.ToString("C2")
  116.  
  117.         'Calculates the tax
  118.         salesTax = totalPrice * 0.05
  119.         'displays Tax in text box
  120.         txtTax.Text = salesTax.ToString("C2")
  121.  
  122.         'Calculates total cost of purchase including Tax and shipping
  123.         totalCost = totalPrice + shipCost + salesTax
  124.         'Displays total cost in text box
  125.         txtTotalCost.Text = totalCost.ToString("C2")
  126.  
  127.  
  128.  
  129.     End Sub
  130.  
  131.     Private Sub ComputeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComputeToolStripMenuItem.Click
  132.  
  133.         'When the compute button is selected the cost calculation is made
  134.         Call Compute()
  135.  
  136.     End Sub
  137.  
  138.  
  139.     Private Sub CalculateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateToolStripMenuItem.Click
  140.  
  141.         'Ensures that the clear button is not available unless a value is in the appropriate text boxes
  142.         If txtOrderQuant.Text = Nothing Then
  143.             menuItemClear.Enabled = False
  144.         Else : menuItemClear.Enabled = True
  145.         End If
  146.  
  147.         If txtShipCost.Text = Nothing Then
  148.             menuItemClear.Enabled = False
  149.         Else : menuItemClear.Enabled = True
  150.         End If
  151.  
  152.         If txtTax.Text = Nothing Then
  153.             menuItemClear.Enabled = False
  154.         Else : menuItemClear.Enabled = True
  155.         End If
  156.  
  157.         If txtTotalCost.Text = Nothing Then
  158.             menuItemClear.Enabled = False
  159.         Else : menuItemClear.Enabled = True
  160.         End If
  161.  
  162.     End Sub
  163.  
  164.     Private Sub TextClear()
  165.  
  166.         'Clears all of the text boxes used in calculating cost
  167.         txtOrderQuant.Text = Nothing
  168.         txtShipCost.Text = Nothing
  169.         txtTax.Text = Nothing
  170.         txtTotalCost.Text = Nothing
  171.  
  172.  
  173.     End Sub
  174.  
  175.     Private Sub menuItemClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuItemClear.Click
  176.  
  177.         'When the clear button is selected the calculation boxes are cleared
  178.         Call TextClear()
  179.  
  180.     End Sub
  181.  
  182.     Private Sub ByProductIDToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ByProductIDToolStripMenuItem.Click
  183.  
  184.         'hides the product description label and combo box when this option is selected
  185.         lblProductIDCombo.Visible = True
  186.         lblPurchProdDesc.Visible = False
  187.  
  188.         cmbProductID.Visible = True
  189.         cmbProdDesc.Visible = False
  190.     End Sub
  191.  
  192.     Private Sub ByProductDescriptionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ByProductDescriptionToolStripMenuItem.Click
  193.  
  194.         'hides the Product ID combo box and label when this button is selected.
  195.         lblProductIDCombo.Visible = False
  196.         lblPurchProdDesc.Visible = True
  197.  
  198.         cmbProductID.Visible = False
  199.         cmbProdDesc.Visible = True
  200.  
  201.     End Sub
  202.  
  203.     Private Sub RecordsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RecordsToolStripMenuItem.Click
  204.  
  205.         'ensure that the accept order button is disabled unless there has been a calculation made.
  206.         If txtTotalCost.Text = Nothing Then
  207.  
  208.             MenuItemAccept.Enabled = False
  209.         Else
  210.             MenuItemAccept.Enabled = True
  211.  
  212.         End If
  213.  
  214.     End Sub
  215.  
  216.     Private Sub MenuItemAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemAccept.Click
  217.  
  218.  
  219.  
  220.  
  221.     End Sub
  222. End Class
  223.  
  224.  
The Last Private Sub MenuItemAccept click is the action that would insert the data to the table, and then I also need toe datagrid view to refresh and show the changes.

Thanks
Mar 29 '07 #1
0 1260

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Amir Hardon | last post by:
I'm new to DOM and can't figure out this thing: I'm trying to add a row to a table with a form field in one of it's cells, but if I'm appending the field to a form it gets out of the table. Can...
11
by: Bobbak | last post by:
Hello All, I have these tables (lets call it ‘EmpCalls', ‘EmpOrders', and ‘Stats') that each contain the list of EmployeeIDs, I want to be able to create a Module in which I could call in my VB...
8
by: Raven | last post by:
Hello, I get a error message when I try to Add data in a relational Access Database. This is the error message: "You cannot add or change a record because a related record is required in...
2
by: David | last post by:
Hi, I have an order form which has a field 'ProductID'. This form has a button on each record to open a new form linked by ProductID. This new form is a continuous form and obviously, only...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Tyler Carver | last post by:
I am trying to use some dynamic controls that are built and then added to tables. The problem that I am having is the timing of when I can populate the controls and have the state remain after a...
0
by: Luis Esteban Valencia | last post by:
Hello I wrote a program with code behind in C# to add row into table dynamically and the program worked very well in .Net Framework 1.1. When I run this program in .Net Framework 2.0 beta...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
7
by: Miro | last post by:
Im a VB Newbie so I hope I'm going about this in the right direction. I have a simple DB that has 1 Table called DBVersion and in that table the column is CurVersion ( String ) Im trying to...
3
by: john | last post by:
In my form (table A) I have subform (table B (only 2 fieds: ID and App_name) where table A -Table B are linked 1XM. To be able to add a record in the subform I want to use a lookup form since the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.