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
Goran Bibic
482
2.9k
198.1k
Increment quantity if have value from textbox in datagrid c#
Nov 18 2018 8:29 AM
Some little help.
Need if exist in datagrid value from textbox1 ( column name: bar_code) to increment cell kolicina(quantity eng.) + 1
private
void
prijavaAction()
{
int
sno = dataGridView1.Rows.Count + 1;
SqlConnection con =
new
SqlConnection(cs);
if
(textBox1.Text.All(
char
.IsDigit))
{
string
queryString =
"select bar_kod, ime, cijena_sa_porezom from roba_usluge WHERE bar_kod = '"
+ textBox1.Text +
"'"
;
// pronaci artikl u bazi
using
(SqlConnection connection =
new
SqlConnection(cs))
{
SqlCommand command =
new
SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
var itemAndPrice = textBox1.Text;
if
(reader.Read())
{
var index = dataGridView1.Rows.Add();
dataGridView1.Rows[index].Cells[
"redni_broj"
].Value = index + 1;
dataGridView1.Rows[index].Cells[
"bar_kod"
].Value = reader[
"bar_kod"
].ToString();
dataGridView1.Rows[index].Cells[
"naziv_artikla"
].Value = reader[
"ime"
].ToString();
dataGridView1.Rows[index].Cells[
"cijena"
].Value = reader[
"cijena_sa_porezom"
].ToString();
dataGridView1.Rows[index].Cells[
"kolicina"
].Value =
"1"
;
foreach
(DataGridViewRow g1
in
dataGridView1.Rows)
{
g1.Cells[
"ukupno"
].Value = (Convert.ToDouble(g1.Cells[
"kolicina"
].Value) * Convert.ToDouble(g1.Cells[
"cijena"
].Value)).ToString(
"0.00"
);
g1.Cells[
"kolicina"
].Value = Convert.ToInt32(g1.Cells[
"kolicina"
].Value) + 1;
}
}
else
{
MessageBox.Show(
"Bar kod ne postoji u bazi!"
,
"Obavještenje"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Text =
""
;
}
}
}
else
{
MessageBox.Show(
"Bar kod ne postoji ili nije bar kod!"
,
"Obavještenje"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Text =
""
;
}
}
Reply
Answers (
12
)
Insert from one to another datagrid values C#
Need some help to read this XML ....XDocument?X XmlDocument?