Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello. My windows form application keeps showing the same results regardless what integer I enter. The results being displayed is the first invoice id in
Hello. My windows form application keeps showing the same results regardless what integer I enter. The results being displayed is the first invoice id in my table. It's not suppose to do that. It's suppose to display the results base on the invoice id I enter, and if I enter an invoice id that's not in my table, then it's suppose to show an exception message. What am I doing wrong and how can I fix it?
My Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; namespace InvoiceLineItems { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void fillByInvoiceIDToolStripButton_Click(object sender, EventArgs e) { try { int InvoiceID = Convert.ToInt32( invoiceIDToolStripTextBox.Text); this.invoiceLineItemsTableAdapter.FillByInvoiceID( this.MMABooksDataSet1.InvoiceLineItems, InvoiceID); this.invoicesTableAdapter.FillByInvoiceID( this.MMABooksDataSet1.Invoices, InvoiceID); if (invoiceLineItemsBindingSource.Count > 0) this.invoicesTableAdapter.FillByInvoiceID( this.MMABooksDataSet1.Invoices, InvoiceID); else MessageBox.Show("No invoice found with this ID. " + "Please try again.", "Invoice Not Found"); } catch (FormatException) { MessageBox.Show("Invoice ID must be an integer.", "Entry Error"); } catch (SqlException ex) { MessageBox.Show("Database error # " + ex.Number + ": " + ex.Message, ex.GetType().ToString()); } } } }
Preview Data ? x Parameters: Name + Type Value No parameters are defined on the selected object. Select an object to preview: Form1 MMABooksDataSet MMABooksDataSet1 MMABooksDataSet1 InvoiceLineltems Fill, GetData 0 FillBylnvoicelDO Invoices Selected object: MMABooksDataSet 1. InvoiceLineItems. Fill By Invoice Target DataSet: Preview Results: InvoiceID Product Code Item Total Quantity 1 18 A46V 57.5000 18 DBIR 1 42.0000 18 VB15 1 23 A46V UnitPrice 57.5000 42.0000 56.5000 57.5000 57.5000 57.5000 57.5000 57.5000 1 26 A46V 1 56.5000 57.5000 57.5000 57.5000 57.5000 57.5000 27 A46V 1 28 A46V 1 29 A46V 1 Columns: 5 Rows: 60 Close Preview Data ? x Parameters: Name + Type Value No parameters are defined on the selected object. Select an object to preview: Form1 MMABooksDataSet MMABooksDataSet 1 MMABooksDataSet1 InvoiceLineltems Invoices Fill, GetData 0 FillBylnvoicelDO 000 Selected object: MMABooksDataSet 1. Invoices.Fill By InvoiceID () Target DataSet: Preview Results: InvoicelD Sales Tax Invoice Total Product Total 156.0000 57.5000 Shipping 6.2500 18 11.7000 173.9500 23 4.3125 3.7500 65.5625 26 InvoiceDate 11/13/2015 11/13/2015 11/13/2015 11/13/2015 11/13/2015 11/13/2015 57.5000 4.3125 3.7500 65.5625 27 4.3125 3.7500 65.5625 28 4.3125 65.5625 57.5000 57.5000 57.5000 57.5000 57.5000 3.7500 3.7500 29 4.3125 65.5625 30 11/13/2015 4.3125 3.7500 65.5625 65.5625 31 11/13/2015 4.3125 3.7500 Columns: 6 Rows: 41 Close - Invoice Line Items Invoice ID: 200 Get Invoice Invoice Date: 11/13/2015 Product Total: 156.0000 Sales Tax: 11.7000 Shipping: 6.2500 Invoice Total: 173.9500 Product Code Quantity 1 A46V Unit Price 57.5000 42.0000 56.5000 Item Total 57.5000 42.0000 56.5000 1 DB1R VB15 1 Preview Data ? x Parameters: Name + Type Value No parameters are defined on the selected object. Select an object to preview: Form1 MMABooksDataSet MMABooksDataSet1 MMABooksDataSet1 InvoiceLineltems Fill, GetData 0 FillBylnvoicelDO Invoices Selected object: MMABooksDataSet 1. InvoiceLineItems. Fill By Invoice Target DataSet: Preview Results: InvoiceID Product Code Item Total Quantity 1 18 A46V 57.5000 18 DBIR 1 42.0000 18 VB15 1 23 A46V UnitPrice 57.5000 42.0000 56.5000 57.5000 57.5000 57.5000 57.5000 57.5000 1 26 A46V 1 56.5000 57.5000 57.5000 57.5000 57.5000 57.5000 27 A46V 1 28 A46V 1 29 A46V 1 Columns: 5 Rows: 60 Close Preview Data ? x Parameters: Name + Type Value No parameters are defined on the selected object. Select an object to preview: Form1 MMABooksDataSet MMABooksDataSet 1 MMABooksDataSet1 InvoiceLineltems Invoices Fill, GetData 0 FillBylnvoicelDO 000 Selected object: MMABooksDataSet 1. Invoices.Fill By InvoiceID () Target DataSet: Preview Results: InvoicelD Sales Tax Invoice Total Product Total 156.0000 57.5000 Shipping 6.2500 18 11.7000 173.9500 23 4.3125 3.7500 65.5625 26 InvoiceDate 11/13/2015 11/13/2015 11/13/2015 11/13/2015 11/13/2015 11/13/2015 57.5000 4.3125 3.7500 65.5625 27 4.3125 3.7500 65.5625 28 4.3125 65.5625 57.5000 57.5000 57.5000 57.5000 57.5000 3.7500 3.7500 29 4.3125 65.5625 30 11/13/2015 4.3125 3.7500 65.5625 65.5625 31 11/13/2015 4.3125 3.7500 Columns: 6 Rows: 41 Close - Invoice Line Items Invoice ID: 200 Get Invoice Invoice Date: 11/13/2015 Product Total: 156.0000 Sales Tax: 11.7000 Shipping: 6.2500 Invoice Total: 173.9500 Product Code Quantity 1 A46V Unit Price 57.5000 42.0000 56.5000 Item Total 57.5000 42.0000 56.5000 1 DB1R VB15 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started