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
484
2.9k
196.7k
Data Reader error c#
Apr 3 2018 4:40 AM
If type value non bar code active is line 49 and no have problems multiple times...
Whene coplue times wrong bar code value I have error line 25 on code
If is bar code from database ok working fine, if is bar code not ok firs time is ok, if wronf two times bar code errorr...
Error is
INVALID ATTEMP TO READ WHEN NO DATA IS PRESENT
private
void
prijavaAction()
{
SqlConnection con =
new
SqlConnection(cs);
if
(textBox1.Text.All(
char
.IsDigit))
{
string queryString =
"SELECT [ime_prezime] FROM dbo.radnici WHERE bar_kod = '"
+ textBox1.Text +
"'"
;
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(
"#2EFF36"
);
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
{
if
(reader.Read())
{
//Insert into
}
else
{
//update
}
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 (
26
)
How to set id for Button in code behind in Xamarin Android
Adding References in .Net Core Applications