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
Asyraf MN
NA
28
7.5k
How to check id in database and display the name on label
Mar 22 2018 1:43 AM
I'm working on the Registration page for Lucky Draw system.So the process for registration is user need to scan their barcode using usb barcode scanner. I stuck on that part which i cannot check the employee id on database after user scan or type in the textbox. I also want to display the employee name after scan the barcode.Can anyone give me some ideas/solution.
Below is my database:
Code :
using
System;
using
System.Collections.Generic;
using
System.Data;
using
System.Data.SqlClient;
using
System.IO;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public
partial
class
Attendance : System.Web.UI.Page
{
SqlCommand cmd =
new
SqlCommand();
SqlConnection con =
new
SqlConnection();
string
str;
private
string
connectionString;
protected
void
Page_Load(
object
sender, EventArgs e)
{
con.ConnectionString = @"Data Source= (LocalDB)\MSSQLLocalDB; AttachDbFilename =
C:\Users\Nor Asyraf Mohd No\source\repos\LuckyDraw\LuckyDraw\App_Data\ticket.mdf;
Integrated Security = True";
txtText.Focus();
}
protected
void
btnSave_Click(
object
sender, EventArgs e)
{
idcheck();
using
(SqlConnection connection =
new
SqlConnection(connectionString))
{
using
(SqlCommand command = connection.CreateCommand())
{
command.CommandText =
"UPDATE EMPLOYEES SET Attendance = 'Present' WHERE EMP_ID = @id"
;
command.Parameters.AddWithValue(
"@id"
, txtText.Text);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
}
}
}
public
void
idcheck()
{
string
query =
"select EMP_ID from EMPLOYEES where EMP_ID='"
+ txtText.Text +
"'"
;
SqlDataAdapter ada =
new
SqlDataAdapter(query, con);
DataTable dt =
new
DataTable();
ada.Fill(dt);
if
(dt.Rows.Count > 0)
{
lblError.Text = dt.Rows[0][
"EMP_NAME"
].ToString();
}
}
protected
void
Button1_Click1(
object
sender, EventArgs e)
{
Response.Redirect(
"Default.aspx"
);
}
}
Reply
Answers (
4
)
cannot explicitly call operator or accessor prolblem
web forms not displaying form controls in running mode