formatexception

How to Solve System.FormatException??

旧城冷巷雨未停 提交于 2019-12-12 03:47:46
问题 Tell me how to fix this Exception please, when the transfer occurs between the PC. Exception Thrown : (System.FormatException) A System.FormatException was thrown: "Input string had an incorrect format." In Line : fileSize = Convert.ToInt32(Encoding.UTF8.GetString(byteFileSize)); My whole Code : private void Server() { FileStream fs = null; BinaryWriter bw = null; int fileSize = 0; int bytesReceived = 0; int bufferInt = Int32.Parse(textBoxBYTE2.Text); byte[] bufferByte = new byte[bufferInt];

Why is this code throwing a FormatException?

試著忘記壹切 提交于 2019-12-12 01:58:29
问题 I have written the following code: Dim E_ID As Integer E_ID = Convert.ToInt16(Request.QueryString("ID")) But when it executes, I always get a FormatException : error: Input string was not in a correct format. What could be causing this? i am sending value like this. Protected Sub lnkPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkPrint.Click lnkPrint.Attributes.Add("onclick", "return openBadgeReportPage('" + ddEvent.DataValueField + "','" + ddType.DataValueField +

C# textBox String type -> integer type

Deadly 提交于 2019-12-11 11:08:32
问题 String t = textBox1.Text; int a = int.Parse(t); if( a < 24) { MessageBox.Show("24 over."); textBox1.Clear(); } An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format How can I change String type value to integer type value? 回答1: t must be a string that's parseable to an integer. According to the runtime, it isn't. You can make the code a bit more resilient by using TryParse instead. Something like this:

C# Loading words from Database and adding them to a list of type “Choices”?

南楼画角 提交于 2019-12-11 02:59:16
问题 I have a built a system which loads words from a database table but I need to add those words to a list of type "Choices" (the type that is needed for Grammar Building). This is my code for requesting words to be retrieved from the database: List<string> newWords = new List<string>(); newWords = LexicalOperations.WordLibrary().ToList(); Choices dbList = new Choices(); //Adding them to a Choice List if (newWords.Count != 0) { foreach (string word in newWords) { dbList.Add(word.ToString()); } }

C# FormatException in DataGridView

风流意气都作罢 提交于 2019-12-11 02:34:50
问题 I created a DataGridView with some columns. The order columns only allow users enter int number. It throws the FormatException when I enter "j" (for example) and I try to add try catch to fix the problem, but it looks does not work.. private void Form1_Load(object sender, EventArgs e) { try{ this.sourceTable = new DataTable(TableName); this.sourceTable.Columns.Add(new DataColumn(OrderCol, Type.GetType("System.Int32"))); dataGridView1.DataSource = sourceTable; }catch(FormatException){

Throw a format exception C#

馋奶兔 提交于 2019-12-09 03:38:14
问题 I'm trying to throw a format exception in the instance someone tries to enter a non-integer character when prompted for their age. Console.WriteLine("Your age:"); age = Int32.Parse(Console.ReadLine()); I'm unfamiliar with C# language and could use help in writing a try catch block for this instance. Thanks very much. 回答1: That code will already throw an FormatException . If you mean you want to catch it, you could write: Console.WriteLine("Your age:"); string line = Console.ReadLine(); try {

Formatting TimeSpans

本小妞迷上赌 提交于 2019-12-08 15:01:46
问题 I am trying to format a TimeSpan with the following line of code: .ToString("[d.]hh:mm:ss") It throws a FormatException , but the exception goes away when I remove the : , the [] , and the . . I also cannot include spaces. Does anyone know why this is happening? On this msdn page it clearly states that you can include these characters. I am using .Net framework 4.5.2 btw. Thanks. 回答1: TimeSpan ts = new TimeSpan(5, 10, 44); string test = string.Format("{0:dd\\:hh\\:mm\\:ss\\.ffff}", ts); 回答2:

Why does DateTime.Now.TimeOfDay.ToString(“HH:mm:ss.ffffff”) throw FormatException?

落爺英雄遲暮 提交于 2019-12-03 23:51:18
问题 I'm having a similar problem with FormatException being thrown. My code is simply: void Orders_OnSubmit() { DateTime CurrentTime = DateTime.Now; rtbAdd( "Submitted on " + CurrentTime.Date.ToString("MM/dd/yyyy") + " at " + CurrentTime.TimeOfDay.ToString("HH:mm:ss.ffffff") ); } void rtbAdd(String S) { DefaultDelegate del = delegate() { rtb.AppendText(S + "\n"); }; this.Invoke(del); } What's wrong here? Is this a threading issue? 回答1: There's no need to explicitly access the Date and TimeOfDay

System.FormatException in C#

為{幸葍}努か 提交于 2019-12-02 16:38:33
问题 I keep getting a FormatException in each of the cases on the line where I try to assign the value for the sale variable. Anyone know what I am doing wrong? I am supposed to make this console program as homework to learn about loops, but I am finding out more about other things. It is supposed to keep a running tab of salesperson's commission based a a 10% commission of each sale. Anyways, here is the code: using System; using System.Collections.Generic; using System.Linq; using System.Text;

Parsing a DBNULL value into double

自闭症网瘾萝莉.ら 提交于 2019-12-02 05:41:02
I use the following line to convert the datarow value into double. double.parse(Convert.ToString(datarow)); If the datarow is DBNULL , I am getting the following exception: 'double.Parse(Convert.ToString(data))' threw an exception of type 'System.FormatException' How to handle this one without using tryparse. Another alternative would be to check if the datarow is DBNull : double d = datarow is DBNull ? 0 : double.Parse(Convert.ToString(datarow)); This way, you do not need to check for DBNull.Value DBNull can't be cast or parsed to double (or int , decimal , etc), so you have to check if