Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
How to retrieve Distinct strings from comparing two Arrays?
Venkatesh Shiga
Jan 22 2018 6:06 AM
162
Reply
I want to retrieve Absent student names from sql database. I have a Listbox in which i have Present student Rfid data (Something like 42 39 A0 11), I have stored the student details along with Rfid in database as nvarchar(1500) datatype.
Using the present stud id in list box i want to retrieve absent students name in an array.
I used NOT IN condition in where but i was not able to retrieve
Then i thought of using for loops to match the get the students who's id was not in the Listbox
But still I am losing the values and not getting proper absent students Id.
private
void
checkabst_Click(
object
sender, EventArgs e)
{
string
[] present =
new
string
[3];
string
[] absent =
new
string
[3];
string
[] allstd =
new
string
[3];
List<
string
> total =
new
List<
string
>();
using
(SqlConnection con =
new
SqlConnection(cs))
{
SqlCommand cmd =
new
SqlCommand(
"Select Rfid_Uid From Studetails"
, con);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while
(sdr.Read())
{
total.add(sdr[0].ToString());
}
allstd=total.toArray();
for
(
int
i=0;i
{
present[i] = listbox_present.Items[i].ToString();
}
bool
isfound =
false
;
for
(
int
i = 0; i < 3; i++)
{
isfound =
false
;
for
(
int
j = 0; j < present.Length; j++)
{
if
(allstd[i] == present[j])
{
isfound =
true
;
}
}
if
(!isfound)
{
MessageBox.Show(allstd[i]);
}
}
Stuck here from past few days.
I am getting Present as well as the absent student Ids in messagebox.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Difference Between Arrays and Collections ?
display username and password connected?