« first day (1 day earlier)    last day (14 days later) » 

6:16 AM
hey man
 
Good afternoon sir
 
good afternoon to you
 
I assume this time you are confused with the tables. After reading this, I could figure out that you need three tables. Out of 3, your two tables will be primary table viz. (Job and worker) and third table will be transaction table (JobWorkersDetail).. Transaction table will have only two columns i.e. JobID, WorkerID .. let me know if you are on similar lines
 
for your previous reply, yeah i get what you meant there
what I don't get is how can I avoid where comboBox.SelectIndex from sql injection
because it isn't consistent
 
SQL injection is a different problem which I need to teach u
 
6:20 AM
umm
 
first let fix ur SQL table problem
 
okay
 
my good guess is that u r not firing right query on DB
 
actually, I got the correct result
 
great
what is the prbm thne?
then?
 
6:22 AM
but when I bind it to comboBox and delete one item from that table, my checkListBox result messed up
1,2,3,4,5,6 which match the comboBox index 1,2,3,4,5,6
if I delete 1 from my db 2,3,4,5,6 than comboBox index won't match
 
if u are deleting anyitem from DB
 
that's why I don't want to user where job_Id = comboBox.selectedIndex
 
then your combobox will also refresh and will remove that item from combobox.. '
 
right
but not the display value in checkListBox
Let's go back to our previous case (my school problem)

myConn.Open();
string query = "select distinct td.teacherId, chineseName from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId WHERE ad.applicationId = '" + applicationComboBox.SelectedIndex+ "' ";

SqlCommand myTeacherCommand = new SqlCommand(query, myConn);

//reading the value from the query
 
try comboBox.selectedvalue
 
6:25 AM
I did something like this remember?
 
instead of comboBox.selectedIndex
 
letme try
 
sorry to keep bothering you :/
 
Its okay buddy
dont worry about that
 
6:29 AM
:)
 
Teaching is a process of self-learning .. so by asking you are teaching me
 
that's make me feel better haha
 
very nice, I need to look at that
 
ok... is problem gone?
 
6:31 AM
i keep getting messed up with the difference between these 2
yeah :D
 
or u need time to try it on your own
 
yeah the problem is gone now. post you answer so I can accept it
 
Selected Index always return index.. starting from 0 or 1.. whatever
 
i see
SelectedItem return a string right?
 
And selectedvalue will return you the value that you are binding from DB
 
6:32 AM
I see
 
SelectedItem returns both.. a smarter version of earlier versions..
 
ahh
When binding data to db will you suggest to use valueMember and displayMember instead of while(dr.Read())? since they are pretty much the same
 
mean? didnt get it
 
like you know you can do

string query = "select applicationId, applicationName from application_detail";
SqlDataAdapter da = new SqlDataAdapter();
myConn.Open();
DataTable dt = new DataTable();

SqlCommand command = new SqlCommand(query, myConn);

SqlDataReader reader = command.ExecuteReader();

dt.Load(reader);

DataRow Drw;
Drw = dt.NewRow();
Drw.ItemArray = new object[] { 0, "<----------Select an application -------> " };
dt.Rows.InsertAt(Drw, 0);

applicationComboBox.DataSource = dt;
applicationComboBox.ValueMember = "applicationId";
this
to get the value from db
or you can do

while (dr.Read())
{
//column is 1 in Application_Detail Data
string appName = dr.GetString(1);
applicationComboBox.Items.Add(appName);


}
dr.Close();*/
this
which one is better? It seems they are pretty much the same
 
First one
SQLDataReader keeps the DB connection alive while you read the data from it
while first method is disconnected.. it first fetch the data from DB and close the connection.. like fetch whole content in one trip to DB.. and allow you to manipulate it later
 
6:38 AM
I see. I am not that sure because I saw some people use the second one
 
SQLDataReader is slow..
 
I see
 
You're a kid, otherwise I can send you a document to understand coding practice
 
haha
 
6:43 AM
nice. thanks man
this is a good reference
 
You're welcome
Good day
 
you too
 
 
10 hours later…
4:27 PM
hey
 
yeah
now tell me in simple plain english what u need..
 
here is my checkListBox:

[x]Amy
[]Peter
[]David
[]Amy
[]Amy
[]Jimmy
you can see Amy is selected right
 
yes
go on ...
 
which it should only have one Amy in my parameterList right
 
it depends on your DB data..
if you have more than one value then you will get more data
 
4:31 PM
but this is not the case. I have 3 amy parameterList, Amy 1, Amy2, Amy 3.
Here is my db
 
what data are you getting out of ur db
 
----------------------
ID | firstName
----------------------
1 Amy
2 Peter
3 Amy
4 Amy
I am getting from the firstName
string query = "select distinct firstName, lastName, employeeEmail,
entryYear, leaveYear
from[employee_detail] as ed
LEFT JOIN[department_detail] as dd ON ed.employeeId = dd.employeeId
Where firstName = (" + parameterList + ")";
this is my query
 
ok in short
you have many employees with same name
now what is ur problem
 
now this is my checkListBox that binded from my table

[x]Amy
[]Peter
[]Amy
[]Amy
and I have selected Amy
Which in my excel file it should only appear one Amy with id 1
still make sense?
 
no it will show all amy
 
4:37 PM
why? because I am mapping it by firstName right?
 
why it would display one Amy? when your DB has 3 Amy's .. why are you going on name.. why dont you see it like that you have 3 employees with same name
Either you have only one employee AMY .. or you have 3 employeees with same name
which one is true?
 
I have 3 employees name Amy
You know that there may be other people may Amnesh right
?
or million of people with their first name Hin
but they should have a unique ID like a social secuirty number
 
yes
that is my point
you don't have control over employee name.. but you have control over your SSN or EmpNo or EmpID
 
right
 
So when you were saying that your CheckBoxList is showing 3 Amy .. then I expect that as right
what is the confusion there
 
4:41 PM
Now let's assume the user only want to know one first Amy
Now let's assume the user only want to know one Amy
still with me?
 
why only one Amy?
want to knw? or want to select only one amy
 
because different Amy has different details such as:
ID firstName email salary department
1 Amy amy1@gmail.com 1000 IT support
2 Amy amy2@yahoo.com 20000 Drama
3 Amy amy3@outlook.com 3443322 English
let say this
yes
[x]Amy
[]Peter
[]Amy
[]Amy
 
good
 
I select the first Amy which should only show:
1 Amy amy1@gmail.com 1000 IT support
this
 
so you want your user to select one amy.. but your user doesn't know which amy, right?
 
4:46 PM
but now my problem is


[x]Amy
[]Peter
[]Amy
[]Amy

it display all other three Amy even though the other 2 aren't checked

1 Amy amy1@gmail.com 1000 IT support
2 Amy amy2@yahoo.com 20000 Drama
3 Amy amy3@outlook.com 3443322 English
yeah kinda
does it make sense now?
 
Your english confuse sometimes :P
 
yeah i know :(
it is better to draw lol
 
So your problem is, your user doesn't know which AMY to select out of 3 as in backend they have different information .. or as they are different employees
 
yeah
 
what is big deal in this dear
now give me ur query
 
4:50 PM
 string query = "select distinct firstName, lastName, chineseName, teacherEmail, entryYear, leaveYear, userLoginId, ad.applicationId from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId  LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId Where ad.applicationId = '" + applicationComboBox.SelectedValue + "'  and td.teacherId = (" + parameterList +")";
Here
 
this is wrong query :D
 
just ignore the other join
 
by this query you are filling your checkboxlist?
 
oh woops
hang on this is my checkBoxList query
string query = "select distinct td.teacherId, chineseName from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId WHERE ad.applicationId = '" + applicationComboBox.SelectedValue + "' ";
remember you told me about selected value?
string query = "select distinct td.teacherId, chineseName from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId WHERE ad.applicationId = '" + applicationComboBox.SelectedValue + "' ";

SqlCommand myTeacherCommand = new SqlCommand(query, myConn);

//reading the value from the query
SqlDataReader dr = myTeacherCommand.ExecuteReader();
teacherCB is my checkListBox.
 
I'm not gonna read your whole code
 
4:53 PM
now this is my how I write to my excel
myConn.Open();

//Reading all the value one by one

Excel.Application xlApp = new Excel.Application();



xlApp.Visible = false;

Excel.Workbook xlwb = xlApp.Workbooks.Add(missing);

//Workbook name is whatever the application name is
string WbName = this.applicationComboBox.GetItemText(this.applicationComboBox.SelectedItem);

StringBuilder sb = new StringBuilder(WbName);

sb.Replace("/", "or");
sb.Replace("-", "");
sb.Replace(",", "");

//first worksheet
Excel.Worksheet xlTeacherDetail = xlwb.ActiveSheet as Excel.Worksheet;
 
I read the same code twice thrice these days
 
okay
 
otherwise I'll dream your code
 
don't worry about it, my code work fine
haha
:p
 
so just tell me .. this is your query which you are using to fill your checkbox list
string query = "select distinct td.teacherId, chineseName from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId WHERE ad.applicationId = '" + applicationComboBox.SelectedValue + "' ";
 
4:54 PM
yep
and this is the query I use to get the checkedItems
string query = "select distinct firstName, lastName, chineseName, teacherEmail, entryYear, leaveYear, userLoginId, ad.applicationId from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId Where ad.applicationId = '" + applicationComboBox.SelectedValue + "' and td.teacherId = (" + parameterList +")";
sorry typo mistake

string query = "select distinct firstName, lastName, chineseName, teacherEmail, entryYear, leaveYear, userLoginId, ad.applicationId from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId Where ad.applicationId = '" + applicationComboBox.SelectedValue + "' and chineseName = (" + parameterList +")";
 
omg
you are confusing me
 
sorry :/
 
your check box looks like this
[x]Amy
[]Peter
[]Amy
[]Amy
 
yeah
pretend this is chineseName in my query
 
and u r saying.. u r using this query to fill this check box list
string query = "select distinct firstName, lastName, chineseName, teacherEmail, entryYear, leaveYear, userLoginId, ad.applicationId from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId Where ad.applicationId = '" + applicationComboBox.SelectedValue + "' and chineseName = (" + parameterList +")";
if you will say YES then I'll KILL u
 
4:57 PM
string query = "select distinct td.teacherId, chineseName from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId WHERE ad.applicationId = '" + applicationComboBox.SelectedValue + "' ";
this one lol
 
you just saved yourself
 
haha
 
now change this query to
give me a min
 
man
 
5:03 PM
sup
 
string query = @"select td.teacherId as ID, chineseName + ' ' + email as Name from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId WHERE ad.applicationId = '" + applicationComboBox.SelectedValue + "' ";
enjoy
I removed Distinct
 
I see
 
combined .. name with Email
so now your text will be something like Amy amy1@xxx.com
say something? u der
 
give me a sec
 
take two
tic
two second over
tic
 
5:12 PM
incorrect syntax near ','
nvm i think the other part cause problem
 
no
fire this in sql
select td.teacherId as ID, chineseName + ' ' + email as Name from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId
any error?
 
nope just the other query got error
 
do i also change it in this one as well?

string query = "select distinct firstName, lastName, chineseName, teacherEmail, entryYear, leaveYear, userLoginId, ad.applicationId from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId Where ad.applicationId = '" + applicationComboBox.SelectedValue + "' and chineseName = (" + parameterList +")";
 
for what are you using this query?
 
5:18 PM
this query should to get the checked item
I use parameterList as a parameter to store a list of names
 
ohh but this query will need a major change
first lets execute first query
get that right
 
umm
 
then will focus on this one
 
yep the first query is right
 
string query = @"select td.teacherId as ID, chineseName + ' ' + email as Name from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId WHERE ad.applicationId = '" + applicationComboBox.SelectedValue + "' ";
is this right?
 
5:19 PM
yep
 
show me how ur UI looks
and what time is now in ur clock?
 
it is 1:20am
this is my UI
but I have a holiday tomorrow :)
 
why
 
if you are tired, we can discuss it tmr
National Day of the People's Republic of China
 
ok
we will discuss tomorrow
 
5:22 PM
okay
 
we will discuss means now
uff
where is your AMY stuff in this UI?
 
coool
this is what i wanted
now problem is in
string query = "select distinct firstName, lastName, chineseName, teacherEmail, entryYear, leaveYear, userLoginId, ad.applicationId from[teacher_detail] as td LEFT JOIN[class_detail] as cd ON td.teacherId = cd.teacherId LEFT JOIN[application_teacher] as at ON at.teacherId = td.teacherId LEFT JOIN[application_detail] as ad ON at.applicationId = ad.applicationId Where ad.applicationId = '" + applicationComboBox.SelectedValue + "' and chineseName = (" + parameterList +")";
this query?
 
yep
 
this query is getting items selected in that big Teachers block.. reading them.. and filling Student Grades or classes?
 
5:25 PM
yep
acutally don't worry about filling grade or class right now
I am going to change that ui later
 
I'm genuis
 
lol
yes you are :)
 
I'll tell you what is wrong with this query.. and then I'll leave things on ur abilities
 
okay
 
you are still using ParameterList as you were using earlier
 
5:26 PM
yep
 
but earlier when you were binding, then you were getting only name from Teachers block..
 
yes
 
which directly existed in one of your column... so that's why your DB were returning right data
 
yes
 
Now situation has changed a bit.. You have clubbed Name with Email in your Teachers block.. to differentiate between teachers who have same name
 
5:28 PM
yep
 
now ParametersList must be getting list (name & email) which directly doesn't exist in DB :D
thats why your code is breaking
 
I see
 
and this is very easy to fix KID ..
Get me a chocolate next time..
 
lol sure I will haha
 
If you need then I can tell you the logic
else I want you to try once on ur own to fix this.. which is very easy
 
5:29 PM
okay
 
and this doesn't have anything to deal with your current question posted on SO
 
on the query right?
 
And I think I'm the only one who is answering your questions on SO.. and soon SO will catch me for fraud
this question
1
Q: How to get the value of the checkListBox

DragonBornI am working on a windows form application and I have a checkListBox that is binded to my database. I am using parameter method to store the selected Text. However, I want to get the primary key of that item similar to comboBox.SelectedValue instead of the Text. Are there way to do this? Here is...

 
yes
 
this question has nothing to do with new problem :P
that question got solved when you added name with email to make proper differentiation
 
5:31 PM
i see
now i just need to make the query the same as the previous one right?
 
this is on u
do you want me to tell u the logic?
if u do then i can
but i dont want to..
 
okay I will try it on my own
:)
 
yes
in that way you will learn
I can tell you the logic.. but that is of no use Hin
 
yeah i know that
thanks again. I am going to sleep. It is 1:30am :/
have a good night
 
i'm posting answer
 
5:34 PM
okay
 
give me a min
ans posted
 
there
 
Good Night
 
anyways. Good night :)
will send you chocolate sometime hahaha
 

« first day (1 day earlier)    last day (14 days later) »