TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chidiebere Mgbemena
NA
179
14.4k
Add button is not clicking/adding when adding a product
Apr 22 2020 9:55 AM
Hello guyz,its me again please look at my codes and see why my add button is not adding the numbers to datagridview and i am not getting any error when i debug."it only underlines dr : SqlDataReader dr; It says "its never been used in frmNewBill" I have removed SqlDataReader dr; from the codes still the add button won't add to datagridview. Below are my codes:
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
NSPM_Sales_Invoice {
public
partial
class
frmNewBill: Form {
SqlConnection con =
new
SqlConnection(Properties.Settings.Default.NSPM_Sales_InvoiceCon);
SqlCommand cmd;
SqlDataReader dr;
public
frmNewBill() {
InitializeComponent();
}
private
void
textBox1_TextChanged(
object
sender, EventArgs e) {}
private
void
panel1_Paint(
object
sender, PaintEventArgs e) {}
private
void
tableLayoutPanel1_Paint(
object
sender, PaintEventArgs e) {}
private
void
frmNewBill_Load(
object
sender, EventArgs e) {
cmbDescription.Items.Clear();
con.Open();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText =
"Select ProName from tbl_Products order by ProName asc"
;
cmd.ExecuteNonQuery();
DataTable dt =
new
DataTable();
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
da.Fill(dt);
foreach
(DataRow dr
in
dt.Rows) {
cmbDescription.Items.Add(dr[
"ProName"
].ToString());
}
con.Close();
}
private
void
btnAdd_Click(
object
sender, EventArgs e) {
if
(cmbDescription.Text ==
""
) {
MessageBox.Show(
"Description is Empty"
);
}
else
if
(txtQuantity.Text ==
""
) {
MessageBox.Show(
"Quantity is Empty"
);
}
else
if
(txtUnitPrice.Text ==
""
) {
MessageBox.Show(
"Unit Price is Empty"
);
}
else
if
(txtJobNo.Text ==
""
) {
MessageBox.Show(
"JobNo is Empty"
);
if
(txtDeleteUpdate.Text ==
""
) {
int
row = 0;
dataGridView1.Rows.Add();
row = dataGridView1.Rows.Count - 1;
dataGridView1[
"Description"
, row].Value = cmbDescription.Text;
dataGridView1[
"Quantity"
, row].Value = txtQuantity.Text;
dataGridView1[
"UnitPrice"
, row].Value = txtUnitPrice.Text;
dataGridView1[
"Value"
, row].Value = txtValue.Text;
dataGridView1[
"JobNo"
, row].Value = txtJobNo.Text;
dataGridView1.Refresh();
cmbDescription.Focus();
if
(dataGridView1.Rows.Count > 0) {
dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1];
}
}
else
{
int
i = 0;
DataGridViewRow row = dataGridView1.Rows[i];
row.Cells[1].Value = cmbDescription.Text;
row.Cells[2].Value = txtQuantity.Text;
row.Cells[3].Value = txtUnitPrice.Text;
row.Cells[4].Value = txtValue.Text;
}
cmbDescription.Text =
""
;
txtQuantity.Text =
""
;
txtUnitPrice.Text =
""
;
txtValue.Text =
""
;
txtJobNo.Text =
""
;
}
}
private
void
dataGridView1_RowPostPaint(
object
sender, DataGridViewRowPostPaintEventArgs e) {
this
.dataGridView1.Rows[e.RowIndex].Cells[0].Value = (e.RowIndex + 1).ToString();
}
int
i;
private
void
dataGridView1_CellDoubleClick(
object
sender, DataGridViewCellEventArgs e) {
i = e.RowIndex;
DataGridViewRow row = dataGridView1.Rows[i];
cmbDescription.Text = row.Cells[1].Value.ToString();
txtQuantity.Text = row.Cells[2].Value.ToString();
txtUnitPrice.Text = row.Cells[3].Value.ToString();
txtValue.Text = row.Cells[4].Value.ToString();
txtDeleteUpdate.Text = row.Cells[0].Value.ToString();
}
private
void
btnDelete_Click(
object
sender, EventArgs e) {
if
(txtDeleteUpdate.Text ==
""
) {
MessageBox.Show(
"Select Product to Delete"
);
}
else
{
foreach
(DataGridViewRow row
in
dataGridView1.SelectedRows) {
if
(!row.IsNewRow) dataGridView1.Rows.Remove(row);
}
}
}
}
}
please help its urgently needed. thanks
Reply
Answers (
3
)
Anti-Forgery for security audit.
.Netcore 3.1 support with oracle EF