Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using code like below to change room status. It was working fine because till that time i had to change only single room status.

C#
String sqlr = "update roominformation set status = '0' where roomno = '" + txt_roomno.Text + "'";
new OleDbCommand(sqlr, sr, trans).ExecuteNonQuery();


Now i have multiple rooms in the single text box (txt_roomno) like Single-101,Single-102,Single-103. Before this i have only one room in the text box like Single-101,so there is no problem while updating this.

My Question is now how can i change the status of multiple room numbers from single text box.

It will be like First change the status of Single-101, then Single-102, after that Single-103.

I dont know how to achieve this task..

Please help.
Posted

implement this way:
C#
string text = txt_roomno.Text;
string[] arrRoomNos = text.Split(',');

string roomNosCSV = string.Empty;
foreach (string room in arrRoomNos)
{
    if (roomNosCSV != string.Empty)
        roomNosCSV += ",";

    roomNosCSV += "'" + room.Trim() + "'";
}

String sqlr = "update roominformation set status = '0' where roomno in (" + roomNosCSV + ")";
new OleDbCommand(sqlr, sr, trans).ExecuteNonQuery();
 
Share this answer
 
Comments
Harpreet_125 1-Aug-13 6:37am    
it is not working dude..
Gautam Raithatha 1-Aug-13 6:41am    
Please provide actual query that is generated. And also what is the datatype of roomno column?
Syed Shabeer 1-Aug-13 6:56am    
Gautam's solution will work for sure. Harpreet, why it isnt working in your case?
Adarsh chauhan 1-Aug-13 6:56am    
I agree with Gautam It will generate correct query, if your textbox returns values like Single-101,Single-102,Single-103 .
problem must be somewhere else..
Harpreet_125 1-Aug-13 6:59am    
i am using string(text) data type in access database.. And it is giving error like "No value given for one or more required parameters".
Hello Harpreet,

Take the multiple room number in single variable separated by comma format.
E.g.

C#
String txt_roomno.Text= 'Single-101,Single-102,Single-103' ;


And write your SQL query as below

C#
String sqlr = "update roominformation set status ='0' where roomno in '" + txt_roomno.Text + "'";
 
Share this answer
 
Comments
Gautam Raithatha 1-Aug-13 6:30am    
this will generate query like:
update roominformation set status ='0' where roomno in 'Single-101,Single-102,Single-103'

but it should be like below:
update roominformation set status ='0' where roomno in ('Single-101','Single-102','Single-103')
Harpreet_125 1-Aug-13 6:38am    
i have tried as you said but not able to achieve the task.. i think gautam is saying right..
Adarsh chauhan 1-Aug-13 6:48am    
yup it will not achieve harpreet's goal.
it will generate
update roominformation set status ='0' where roomno in 'Single-101,Single-102,Single-103'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900