last day (16 days later) » 

7:27 AM
Hey again
 
Hi buddy again
your whole code is wrong, sorry
 
oh you mean my query? :(
I am not so sure because I want to get the text of that checkListBox (same project from last time)
 
i mean your whole block, sir
 
umm
 
hang on
 
7:29 AM
okay
 
I'm working on a sample code for u
 
alright, thanks
 
Great, I'm done
now tell me what you need
I assume that you have a CheckListBox which got certain items..
 
right
 
and now you want to check the checked values against your database, right?
So if you checklistbox has four items..
1. US
2. China
3. India
4. UAE
 
7:31 AM
yeah, I want to see if that checked item match
 
and if user elect US and China at run time.. then you want to fetch all the records which has country either US or china.. and so on so forth?
 
yep
This was my original code
 
so in short your whole code block is wrong
 
what a sec
int i = 2;

string index = teacherCB.SelectedItem.ToString();

foreach (var items in teacherCB.CheckedItems)
{

//aud.applicationId = '" + index + "'
//string query = " SELECT * FROM[AppUser_Detail] as aud LEFT OUTER JOIN[Teacher_Detail] as td ON aud.teacherId = td.teacherId LEFT OUTER JOIN[Application_Detail] as ad ON aud.applicationId = ad.applicationId LEFT OUTER JOIN[Class_Detail] as cd ON aud.classId = cd.classId where chineseName = '" + items + "' AND NOT(td.teacherId IS NULL AND cd.classId IS NULL)";
 
7:34 AM
foreach (var items in teacherCB.CheckedItems)
{



string query = "select distinct firstName, lastName, chineseName, teacherEmail, entryYear, leaveYear, userLoginId, class, secondary, 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 chineseName = '" + items + "' ";

myCommand = new SqlCommand(query, myConn);

 
hold on sir
 
alright
 
you don't need to write query like that
 
umm
 
First of all .. understand the flow
 
7:37 AM
I have sent you a screen shot, assume the chineseName is match
 
Ohh u r hing wong again :D
Hin*
 
haha yeah :D
 
ok now forget everything
listen to me
 
alright
 
First of all you have display items in your CLB (checkListBox)
u r done with that
Second you have make selection out of those.. which you can do on UI
third you need to capture all the items which was selected by user ..
and fourth you want to select records from your DB based on user selection
Here you are trying to pull records from DB based on multiple values.. so your = equal operator wont work at all.. you would need to use IN operator
 
7:41 AM
right
 
I wrote this
private void button1_Click(object sender, EventArgs e)
{
string items = string.Empty;
foreach (var item in checkedListBox1.CheckedItems)
{
if (items.Length == 0)
items = item.ToString();
else
items = items + "," + item;

}
MessageBox.Show(items);
}
At the end, items will hold a comma separated list of items which were selected by user
now just plug this value in your query
give me ur query.. which u r using to fetch the records.. only query
 
okay wait
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 = 2
this is the one
 
ok
condition*
this doesn't have condtion on Chinese name
 
okay
chineseName is just nvarchar
 
ok
np
private void button1_Click(object sender, EventArgs e)
{
string items = string.Empty;

foreach (var item in checkedListBox1.CheckedItems)
{
if (items.Length == 0)
items = item.ToString();
else
items = items + "," + item;
}

//make myCommand object and open connection on your own
myCommand = new SqlCommand(query, myConn);

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
check this..
Wong.. I have wrote the code in click event of a button.. so take the code.. add connection open code to this.. and then datareader and other part
 
7:51 AM
okay, I will give it a try
question, what if my applicationId is base on that comboBox selected item
 
combobox will return you multiple items.. means more than one
you again your equal to (=) operator wont work
you would need to make it comma separated
and then use IN operator
I'm stepping out for sometime to grab lunch for me.. if this doesn't help then let me know
 
Where ad.applicationId = '"+applicationComboBox.SelectedIndex+"' something like this in the query wont work?
 
it may work if datatype is right order.. but if you have multiple items selected then it wont work
hold tight.. i need a break
will back in 30 mins or so
 
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.SelectedIndex+"' and chineseName in (@name)";
okay
YEAHH it works like a charm :D
 
great
let me post this as an answer then :D
 
8:01 AM
okay :)
 
u hv a problem
 
what problem? :/
voted
I have one more question. Let say there is a null value (but it is an integer not a string) in a column
I am trying to do something like this
int? l_Year = dr.IsDBNull(5) ? null : dr.GetInt32(5); but it say
'type of conditional cannot be determined.' is this the way to do this?
 
u need to accept also ;\
and never use parameters like ad.applicationId = '"+applicationComboBox.SelectedIndex+"'
 
oh sorry, i was typing that question lol
 
use parameter query always
 
8:04 AM
okay
 
like i Used in above example.. with @name
That is a small problem :D
You should not assign a null value .. NEVER
 
okay :)
 
if u have other problems then let me know
got to go.. bye
 
thank you very much :)
have a good day
 

  last day (16 days later) »