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
197.9k
Select IMAGE from SQL BASE to picturebox C#
Apr 29 2018 1:53 PM
Code working fine
I need to put picture from sql to picturebox in my code
private
void
prijavaAction()
//04.04. final doradjena perfect
{
{
SqlConnection con =
new
SqlConnection(cs);
if
(textBox1.Text.All(
char
.IsDigit))
{
string queryString =
"SELECT [ime_prezime] FROM dbo.radnici WHERE bar_kod = '"
+ textBox1.Text +
"'"
;
// pronaci radnika u bazi
using
(SqlConnection connection =
new
SqlConnection(cs))
{
SqlCommand command =
new
SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
string commanda =
"select case when (SELECT (DATEDIFF(SECOND, Max(vrijemeprijave), GETDATE()) / 60) from dbo.prijava_radnika where status='prijavljen' and radnik= ("
+ queryString +
")) < 5 THEN 1 ELSE 0 END"
;
SqlConnection connection3 =
new
SqlConnection(cs);
SqlCommand command2 =
new
SqlCommand(commanda, connection3);
connection3.Open();
int
broj = Convert.ToInt32(command2.ExecuteScalar());
string commanda2 =
"select case when (SELECT (DATEDIFF(SECOND, Max(vrijemeodjave), GETDATE()) / 60) from dbo.prijava_radnika where status='odjavljen' and radnik= ("
+ queryString +
")) < 5 THEN 1 ELSE 0 END"
;
SqlConnection connection4 =
new
SqlConnection(cs);
SqlCommand command4 =
new
SqlCommand(commanda2, connection4);
connection4.Open();
int
broj2 = Convert.ToInt32(command4.ExecuteScalar());
if
(broj == 1 || broj2 == 1)
{
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml(
"#FD7400"
);
messageLabel.Text =
"Prijava i odjava su blokirani 5 minuta \nza ovog radnika"
;
textBox1.Text =
""
;
}
else
{
try
{
if
(reader.Read())
{
string prijava =
"SELECT count(*) from dbo.prijava_radnika where vrijemeprijave is not null and vrijemeodjave is null and radnik = '"
+ readerresultTextbox.Text +
"' and redni_broj is NULL"
;
SqlCommand provjeraprijaveradnika =
new
SqlCommand(prijava, con);
con.Open();
int
result = Convert.ToInt32(provjeraprijaveradnika.ExecuteScalar());
con.Close();
if
((result == 0))
{
String saveStaff =
"INSERT INTO dbo.prijava_radnika (vrijemeprijave, status, radnik,idfakture) VALUES(@vrijemeprijave,'prijavljen', '"
+ readerresultTextbox.Text +
"',@idfakture)"
;
using
(SqlConnection openCon2 =
new
SqlConnection(cs))
{
using
(SqlCommand querySaveStaff =
new
SqlCommand(saveStaff))
{
querySaveStaff.Connection = openCon2;
querySaveStaff.Parameters.Add(
"@vrijemeprijave"
, SqlDbType.DateTime).Value = DateTime.Now;
querySaveStaff.Parameters.Add(
"@idfakture"
, SqlDbType.Int).Value = id_fakture;
openCon2.Open();
querySaveStaff.ExecuteNonQuery();
openCon2.Close();
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml(
"#2EFF36"
);
// messageLabel.Text = (reader["ime_prezime"].ToString()) + " je prijavljen u \n " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");
messageLabel.Text = (
"Dobro došli na posao...\n"
+ reader[
"ime_prezime"
].ToString()) +
" \nPrijavljeni ste od\n "
+ DateTime.Now.ToString(
"dd.MM.yyyy HH:mm:ss"
);
readerresultTextbox.Text = (reader[
"ime_prezime"
].ToString());
}
}
}
else
{
String updateStaff =
" declare @maxNo integer = 0 select @maxNo = isnull(max(redni_broj), 0) from[dbo].[prijava_radnika] UPDATE[dbo].[prijava_radnika] SET"
+
" [vrijemeodjave] = @vrijemeodjave,[redni_broj] = (@maxNo+1),[status] = 'odjavljen' WHERE radnik = '"
+ readerresultTextbox.Text +
"'and [status] = 'prijavljen'"
;
using
(SqlConnection connection1 =
new
SqlConnection(cs))
{
SqlCommand command1 =
new
SqlCommand(queryString, connection1);
connection1.Open();
SqlDataReader reader1 = command1.ExecuteReader();
connection.Close();
try
{
if
(reader1.Read())
{
using
(SqlConnection openCon3 =
new
SqlConnection(cs))
{
using
(SqlCommand queryupdateStaff =
new
SqlCommand(updateStaff))
{
queryupdateStaff.Connection = openCon3;
queryupdateStaff.Parameters.Add(
"@vrijemeodjave"
, SqlDbType.DateTime).Value = DateTime.Now;
openCon3.Open();
queryupdateStaff.ExecuteNonQuery();
openCon3.Close();
}
}
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml(
"#FFE11A"
);
messageLabel.Text = (reader1[
"ime_prezime"
].ToString()) +
" je odjavljen u \n "
+ DateTime.Now.ToString(
"dd.MM.yyyy HH:mm:ss"
);
}
}
catch
{ }
}
reader.Close();
}
}
else
{
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml(
"#FD7400"
);
messageLabel.Text =
"Radnik ne postoji u bazi! \nProverite vašu karticu ili probajte ponovo!"
;
textBox1.Text =
""
;
}
}
finally
{
}
}
}
}
else
{
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml(
"#FD7400"
);
messageLabel.Text =
"Bar kod nije važeci ili nije bar kod"
;
textBox1.Text =
""
;
}
}
}
Reply
Answers (
2
)
How to Check Table Cell Value
Database structure for advance/due payment