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.2k
Add row in datagrid after select from SQL C#
Oct 21 2018 12:35 PM
Add row in datagrid after select from sql query
First time when select is empty row, second is full row
Some help please
Need when select from db value to insert in datagrid
Query is ok
Problem is from line 22 to line 33
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();
if
(reader.Read())
{
for
(
int
i = 1; i < dataGridView1.Rows.Count; i++)
{
dataGridView1.Rows[i].Cells[
"redni_broj"
].Value = i;
dataGridView1.Rows[i].Cells[
"bar_kod"
].Value = reader[
"bar_kod"
].ToString();
dataGridView1.Rows[i].Cells[
"naziv_artikla"
].Value = reader[
"ime"
].ToString();
dataGridView1.Rows[i].Cells[
"cijena"
].Value = reader[
"cijena_sa_porezom"
].ToString();
}
// dataGridView1.Rows.Add(sno, nazivartikla, 1, cijena, cijena);
dataGridView1.Rows.Add();
reader.Close();
}
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 (
3
)
how get list of data of T variable
C# language working on trying to get some code..begginer