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
The multi-part identifier "System.Data.SqlClient.SqlCommand"
Mar 11 2018 3:03 AM
private void prijavaAction()
{
if (textBox1.Text.All(char.IsDigit))
{
string selektujradnika = "SELECT ime_prezime FROM radnici WHERE (bar_kod LIKE @FIND)";// pronaci radnika u bazi
SqlCommand osobaId = new SqlCommand(selektujradnika);
con = new SqlConnection(cs);
con.Open();
con.Close();
{
con.Open();
osobaId = new SqlCommand(selektujradnika);
osobaId.Connection = con;
osobaId.Parameters.Add(new SqlParameter("@Find", System.Data.SqlDbType.VarChar, 50, "bar_kod")).Value = textBox1.Text;
osobaId.Parameters["@Find"].Value = textBox1.Text;
rdr = osobaId.ExecuteReader();
messageLabel.Text = " ";
readerresultTextbox.Text = " ";
if (rdr.Read()) //prijava radnika
{
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFE11A");
messageLabel.Text = (rdr["ime_prezime"].ToString()) + " je prijavljen u \n " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");
readerresultTextbox.Text = (rdr["ime_prezime"].ToString());
con.Close();
string selektujradnika2 = "SELECT ime_prezime FROM radnici WHERE (bar_kod LIKE @Find)";
SqlCommand osobaId2 = new SqlCommand(selektujradnika2);
con.Open ();
string provjeraprijavestring = "SELECT COUNT (*) FROM dbo.prijava_radnika WHERE radnik= " + osobaId + " and vrijemeodjave is null and status='prijavljen'";// pronaci radnika u bazi
//string provjeraprijavestring2 = "SELECT count(*) FROM dbo.prijava_radnika WHERE vrijemeodjave IS NULL and status = 'prijavljen'";// pronaci radnika u bazi
SqlCommand komandaprijave = new SqlCommand(provjeraprijavestring, con);
int userCount = (int)komandaprijave.ExecuteScalar();
if (userCount == 1)
{
///////////////////////////////////
using (SqlConnection openCon3 = new SqlConnection(cs))
{
SqlCommand comm = new SqlCommand(cs);
comm.CommandText = "select max(brojprijavnice2) from dbo.prijava_radnika";
comm.Connection = openCon3;
openCon3.Open();
rdr = comm.ExecuteReader();
int max = 0;
while (rdr.Read())
{
max = Convert.ToInt32(rdr[0].ToString());
Console.WriteLine(max);
}
openCon3.Close();
String saveStaff = "UPDATE dbo.prijava_radnika SET vrijemeodjave=@vrijemeodjave, brojprijavnice2=" + (max + 1) + " WHERE radnik=" + osobaId;
using (SqlCommand querySaveStaff = new SqlCommand(saveStaff))
{
querySaveStaff.Connection = openCon3;
querySaveStaff.Parameters.Add("@vrijemeodjave", SqlDbType.DateTime).Value = DateTime.Now;
openCon3.Open();
querySaveStaff.ExecuteNonQuery();
openCon3.Close();
// osobaId = new SqlCommand(selektujradnika);
// osobaId.Connection = con;
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#76AB01");
messageLabel.Text = selektujradnika + " je odjavljen u\n" + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");
textBox1.Text = "";
}
}
}
else
{
string saveStaff = "INSERT into dbo.prijava_radnika (vrijemeprijave, radnik, status) VALUES(@vrijemeprijave,@radnik,'prijavljen')";
using (SqlCommand querySaveStaff = new SqlCommand(saveStaff))
{
querySaveStaff.Connection = con;
querySaveStaff.Parameters.Add("@vrijemeprijave", SqlDbType.DateTime).Value = DateTime.Now;
// querySaveStaff.Parameters.Add("@vrijemeodjave", SqlDbType.DateTime).Value = vrijemeodjaveDateTimePicker;
//querySaveStaff.Parameters.Add("@brojprijavnice", SqlDbType.VarChar, 255).Value = brojprijavnice2TextBox.Text;
querySaveStaff.Parameters.Add("@radnik", SqlDbType.VarChar, 255).Value = readerresultTextbox.Text;
// querySaveStaff.Parameters.Add("@id_fakture", SqlDbType.Int).Value = id_fakture;
con.Open();
querySaveStaff.ExecuteNonQuery();
con.Close();
osobaId = new SqlCommand(selektujradnika);
osobaId.Connection = con;
}
}
con.Close();
}
else
{
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#FD7400");
messageLabel.Text = "Ne postoji radnik sa ovim bar kodom";
textBox1.Text = "";
}
}
}
else
{
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#FD7400");
messageLabel.Text = "Bar kod nije važeci ili nije bar kod";
textBox1.Text = "";
}
}
Reply
Answers (
10
)
list of visitors
Why dont work update ///another way