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...
What's wrong with this code? #Java Why I am getting error in : int BusCompare =...
What's wrong with this code? #Java Why I am getting error in : int BusCompare = o1.numberOfBusinesses.compareTo(o2.numberOfBusinesses); public class TypeComparator implements Comparator<Type> { @Override public int compare(Type o1, Type o2) { // return o1.name.compareTo(o2.name); int NameCompare = o1.name.compareTo(o2.name); int BusCompare = o1.numberOfBusinesses.compareTo(o2.numberOfBusinesses); // 2-level comparison using if-else block if (NameCompare == 0) { return ((BusCompare == 0) ? NameCompare : BusCompare); } else { return NameCompare; } } } public class Type implements Comparable<Type> { int id; String name; int...
(JAVA) I have "cannot be resolved or is not a field" error on node.right = y;...
(JAVA) I have "cannot be resolved or is not a field" error on node.right = y; and node.left = x; //BuildExpressionTree.java import java.util.*; import javax.swing.*; import javax.xml.soap.Node; public class BuildExpressionTree {    private Stack stack = new Stack();    private Node node;       public static boolean isOperator(String token){        if(token == "+" || token == "-" || token == "*" || token == "/"){            return true;        }        JOptionPane.showMessageDialog(null, "Invalid token" +...
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 =...
I need to sum a looped listbox in C#. I am adding a snip of my...
I need to sum a looped listbox in C#. I am adding a snip of my code. The user is to input the number of days that were worked. You get paid .01 for the first day and then that amount doubles per day worked. The code I am posting already does what it is supposed to do - it displays a list with the numbers of days worked with the amount of pay for that day listed beside it....
Hi, I'm writing a Java program that prints a grid with circles and squares that have...
Hi, I'm writing a Java program that prints a grid with circles and squares that have letters in them and it is also supposed to print the toString() function to the console window each time the application runs. This toString() function is supposed to show the tile's shape, letter, and color component (or components). Could someone please review and debug my code to help me figure out why my toString() function is not working? import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton;...
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...
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...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT