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
480
2.9k
200.7k
Why dont work update ///another way
Mar 11 2018 1:20 PM
private
void
prijavaAction()
{
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();
try
{
if
(reader.Read())
{
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml(
"#FFE11A"
);
messageLabel.Text = (reader[
"ime_prezime"
].ToString()) +
" je prijavljen u \n "
+ DateTime.Now.ToString(
"dd.MM.yyyy HH:mm:ss"
);
readerresultTextbox.Text = (reader[
"ime_prezime"
].ToString());
}
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
{
string
prijava =
"SELECT count (*) from dbo.prijava_radnika where vrijemeprijave is not null and vrijemeodjave is null and brojprijavnice2 is NULL and radnik="
+ readerresultTextbox.Text;
SqlCommand provjeraprijaveradnika =
new
SqlCommand(prijava);
//con.Open();
if
((prijava !=
null
))
//radi
//if ((prijava !))
{
String saveStaff =
"INSERT INTO dbo.prijava_radnika (vrijemeprijave, status, radnik) VALUES(@vrijemeprijave,'prijavljen',@radnik)"
;
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(
"@radnik"
, SqlDbType.VarChar, 255).Value = readerresultTextbox.Text;
openCon2.Open();
querySaveStaff.ExecuteNonQuery();
openCon2.Close();
}
}
}
else
{
String updateStaff =
"UPDATE dbo.prijava_radnika SET vrijemeprijave=@vrijemeodjave, status='odjavljen' WHERE radnik="
+ provjeraprijaveradnika.ToString();
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();
}
}
}
// Always call Close when done reading.
reader.Close();
}
}
}
else
{
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml(
"#FD7400"
);
messageLabel.Text =
"Bar kod nije važeci ili nije bar kod"
;
textBox1.Text =
""
;
}
}
Reply
Answers (
24
)
The multi-part identifier "System.Data.SqlClient.SqlCommand"
How to print selected checkbox in datagridview and in case n