Question

I am having a problem with this one error. I have to turn this in tonight...

I am having a problem with this one error. I have to turn this in tonight and this is holding me up right now. Just not sure how to fix it. .VS 2019 .net framework windows forms

private void DisplayForm_Load(object sender, EventArgs e)
{
if (File.Exists("Employee.txt"))
{
using (StreamWriter sr = new StreamWriter("employee.txt"))
{
string employeeId = "";
while ((employeeId = sr.ReadLine()) != null)
{
Employee employee = new Employee(employeeId, sr.ReadLine(),
decimal.Parse(sr.ReadLine()), decimal.Parse(sr.ReadLine()));
Employee emp = employee;
employeeListBox.Items.Add(emp);
allEmployee.Add(emp);
}
}
}
else
{
employeeListBox.Items.Add("No Employees entered yet.");
}
}

private void printButton_Click(object sender, EventArgs e)
{
printDocument1.Print();
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int x = 75, y = 75;
foreach (Employee emp in allEmployee)
{
e.Graphics.DrawString(emp.ToString(),
new Font("Courier", 10, FontStyle.Regular),
Brushes.Black, x, y);
y += 14;
}
}

private void closeButton_Click(object sender, EventArgs e)
{
Close();
}

Severity   Code   Description   Project   File   Line   Suppression State
Error   CS1061   'StreamWriter' does not contain a definition for 'ReadLine' and no accessible extension method 'ReadLine' accepting a first argument of type 'StreamWriter' could be found (are you missing a using directive or an assembly reference?)   

This is the section that I am having problems with

private void DisplayForm_Load(object sender, EventArgs e)
{
if (File.Exists("Employee.txt"))
{
using (StreamWriter sr = new StreamWriter("employee.txt"))
{
string employeeId = "";
while ((employeeId = sr.ReadLine()) != null)
{
Employee employee = new Employee(employeeId, sr.ReadLine(),
decimal.Parse(sr.ReadLine()), decimal.Parse(sr.ReadLine()));
Employee emp = employee;
employeeListBox.Items.Add(emp);
allEmployee.Add(emp);
}
}
}
else
{
employeeListBox.Items.Add("No Employees entered yet.");
}
}

private void printButton_Click(object sender, EventArgs e)
{
printDocument1.Print();
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int x = 75, y = 75;
foreach (Employee emp in allEmployee)
{
e.Graphics.DrawString(emp.ToString(),
new Font("Courier", 10, FontStyle.Regular),
Brushes.Black, x, y);
y += 14;
}
}

private void closeButton_Click(object sender, EventArgs e)
{
Close();
}

Homework Answers

Answer #1

First include the namespace"using System.IO;"

Please use following line instead of StreamWriter. As StreamWriter does not have ReadLine() methods it throws an error.

using (StreamReader sr = new StreamReader("employee.txt"))

As you have provided part of your code, I cud not provide the complete running code. But above two corrections would fix your issue.

Please let me know if you need any further help.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Hello. I have an assignment that is completed minus one thing, I can't get the resize...
Hello. I have an assignment that is completed minus one thing, I can't get the resize method in Circle class to actually resize the circle in my TestCircle claass. Can someone look and fix it? I would appreciate it! If you dont mind leaving acomment either in the answer or just // in the code on what I'm doing wrong to cause it to not work. That's all I've got. Just a simple revision and edit to make the resize...
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...
This is the java code that I have, but i cannot get the output that I...
This is the java code that I have, but i cannot get the output that I want out of it. i want my output to print the full String Form i stead of just the first letter, and and also print what character is at the specific index instead of leaving it empty. and at the end for Replaced String i want to print both string form one and two with the replaced letters instead if just printing the first...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
For some reason I followed the steps in my project and I am getting the incorrect...
For some reason I followed the steps in my project and I am getting the incorrect output and when I am submitting it, it gives me compilation error. Printing empty array -- next line should be blank Testing append: Shouldn't crash! Should print 100 through 110 below, with 110 on a new line: 100 101 102 103 104 105 106 107 108 109 110 Checking capacity of new array: OK Append test #2: Should print 100 through 120 below, on...
I am making a game like Rock Paper Scissors called fire water stick where the rules...
I am making a game like Rock Paper Scissors called fire water stick where the rules are Stick beats Water by floating on top of it Water beats Fire by putting it out Fire beats Stick by burning it The TODOS are as follows: TODO 1: Declare the instance variables of the class. Instance variables are private variables that keep the state of the game. The recommended instance variables are: 1. 2. 3. 4. 5. 6. A variable, “rand” that...
I am trying to make a program in C# and was wondering how it could be...
I am trying to make a program in C# and was wondering how it could be done based on the given instructions. Here is the code that i have so far... namespace Conversions { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML...
Homework Draw class diagrams for your HW4 - the Tetris Game shown below: Part 1: UML As a review, Here are some links to some explanations of UML diagrams if you need them. • https://courses.cs.washington.edu/courses/cse403/11sp/lectures/lecture08-uml1.pdf (Links to an external site.) • http://creately.com/blog/diagrams/class-diagram-relationships/ (Links to an external site.) • http://www.cs.bsu.edu/homepages/pvg/misc/uml/ (Links to an external site.) However you ended up creating the UML from HW4, your class diagram probably had some or all of these features: • Class variables: names, types, and...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT