Предупредите меня, почему результаты меняются при каждом втором звонке?
here we using if statement and it's work fine for first time then when i enter barcode and pressed enter again it's going direct to else statement it's mean shown me error message under as we see on else statement and i think it's not repeat whole statement as new process because i'm sure from condition it's true and it shouldn't go to else statement but in third time when i try enter barcode and check from condition it's work fine like first time and then in forth time show me error again why error message shown on every second try block is this line:
<pre>if (dt.Rows.Count > 0)
here whole code
<pre>private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (checkBox1.Checked) { if (qtystate == true) { DataTable dt; barcode = textBox1.Text; dt = pro.GetProdcutBar(textBox1.Text); if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { barcode = row[0].ToString(); itemno = row[1].ToString(); itemname = row[2].ToString(); salespric = row[3].ToString(); costprice = row[4].ToString(); } cont.addprodcuttocount(Convert.ToString(barcode), Convert.ToString(itemno), Convert.ToString(itemname), Convert.ToString(salespric), Convert.ToString(costprice), "1", DateTime.Now, SystemInformation.ComputerName); refershgridview(); //sum qty try { int sum = 0; for (int i = 0; i < dataGridView1.Rows.Count; ++i) { if (Convert.ToString(dataGridView1.Rows[i].Cells[1].Value) == textBox1.Text) { sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[6].Value); } } label3.Text = "Barcode " + barcode + " - " + "Item NO" + itemno + " - " + "item name " + itemname + " - " + "qty " + sum.ToString(); } catch { } barcode = ""; itemno = ""; itemname = ""; salespric = ""; costprice = ""; qtyitem = ""; textBox1.Clear(); textBox1.Focus(); } else { MessageBox.Show("00barcode not found", "barcode", MessageBoxButtons.OK, MessageBoxIcon.Stop); barcode = ""; itemno = ""; itemname = ""; salespric = ""; costprice = ""; qtyitem = ""; textBox1.Clear(); textBox1.Focus(); } } } } }
Что я уже пробовал:
я пытаюсь удалить блоки try, и ничего не происходит
F-ES Sitecore
Используйте отладчик для пошагового просмотра кода, чтобы увидеть, что происходит.
mohammed mqi
когда я отлаживаю свой код это дает мне один результат
Richard MacCutchan
Почему вы используете Convert.ToString
по всем элементам, которые ранее были возвращены в Строковой форме? Также вы устанавливаете barcode
равный textBox1.Text
, но затем используйте тот же самый текст для создания вашего datatable
.
mohammed mqi
спасибо Ричарду за повтор, который я использую Convert.Метод toString, чтобы быть более страховать и потому какое-то время я проснулся, float значение
а про штрих-код, равный элемент textbox1.Текст, потому что я использую текстовое поле textbox1.Текст для ручного ставить кол манул в другом случае после получения штрих-кода во-первых, если кол-во пустой он будет проходить кол-во в textbox1.Текст когда корпус переключателя для вставки кол-во