|
If i've got the following code and its selecting the following values
C0603~A81_01
C0603~A81
how can i change it so that it splits these two values up
at the moment it is reading it as C0603~A81_01C0603~A81
thanks in advance
string roomcodeselect = "Select room_code from room_types where room_code like '" + room_code + "%' ORDER BY room_code DESC";
SqlCommand cmdroomcode2 = new SqlCommand(roomcodeselect, con2);
StringBuilder htmlStr_room_code5 = new StringBuilder("");
SqlDataReader readerroomcode = cmdroomcode2.ExecuteReader();
while (readerroomcode.Read())
{
htmlStr_room_code5.Append(readerroomcode["room_code"]);
}
lbtest2.Text = htmlStr_room_code5.ToString();
Session["sessiontest1"] = lbtest2.Text.ToString();
//string test2 = (string)Session["Sessiontest1"];
db = Session["sessiontest1"].ToString(); // "jh00~pr11_01";
if (db.Contains("_"))
{
string[] split = db.Split('_');
string s_number = split[1];
int i_number = Int32.Parse(s_number);
i_number++;
s_number = i_number.ToString("00");
db = split[0] + "_" + s_number;
}
|
|
|
|
|
I only gave a cursory glance, but the problem seems to be here: htmlStr_room_code5.Append(readerroomcode["room_code"]); You will have to add a statement that says htmlStr_room_code5.Append(Environment.NewLine); to your loop.
Having said that, there's a lot more to correct. Inline queries are frowned upon; I suggest you read up on Sql injection.
Cheers,
Vikram.
"If a trend is truly global, then that trend ought to be visible across ANY subset of that data" - fat_boy
|
|
|
|
|
Like Virkram said, you are creating a string with all the values that match the LIKE statement. Either split each value returned, or use a WHERE room_code = 'value'; since im guessing room_code is unique, thus should only return 1 value.
Also, on a side note, maybe have a look @ http://msdn2.microsoft.com/en-us/library/ms229002.aspx[^].
Its ALOT easier to read code when you name objects with the camel/pascal naming convention eg: readerRoomCode instead of readerroomcode.
Regards,
Gareth.
|
|
|
|
|
Hi
I have a radiobutton list, how do i specify in the c# to enable disbable one of the items in the list
thanks
|
|
|
|
|
<br />
private void DisableRadioButton()<br />
{<br />
RadioButtonToDisable.Enabled = false;<br />
}<br />
now that wasn't too hard was it? Of course, you can go wild and actually pass a reference to the particular radio button you want to disable and disable that one.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
No your post disables the whole of the radiobuttonlist
I just want to disable one of the items in the list and I cannot find the correct syntax to do so
maybe you should read my original post again
|
|
|
|
|
sorted it myself:
RadioButtonList_audit.Items[0].Enabled = true;
thanks for all your wisdom
|
|
|
|
|
Actually, it only disables one, the one named "RadioButtonToDisable".
As is, the addendum to the post says that you can expand on it where you can pass a parameter so you can choose which one you want to disable.
so something like this could exist:
enum eRadioButtonList
{
RadioButton1 = 1,
RadioButton2 = 2,
RadioButton3 = 3
}
private void DisableRadioButton(eRadioButtonList rbl)
{
switch(rbl)
{
case 1:
RadioButton1.Enabled = false;
Break;
case 2:
RadioButton2.Enabled = false;
Break;
case 3:
RadioButton3.Enabled = false;
Break;
}
}
There, did your homework
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
ok i think im misunderstanding you or vice-versa
i had:
<asp:radiobuttonlist id="RadioButtonList_audit" runat="server" visible="false">
<listitem text="Default Audit Settings" value="defaultAudit" enabled="true/">
<listitem text="Create Audit History With Reasons For Changes" value="detailedAudit" />
</listitem></asp:radiobuttonlist>
i wanted to disable listitem text"Create Audit History With Reasons For Changes" etc...
i did
RadioButtonList_audit.Items[1].Enabled = false;
it worked.. problem solved
hmm......
|
|
|
|
|
Just an aside, but you should probably access the items through Id rather than by index (ie, give each listitem an id attribute, and use RadioButtonList_audit.Items["someId"].Enabled). That way, if you add or reorder the options later on, your code won't break. Note that I did not test the above, but only present it as a logical solution. The actual syntax of using the id may vary.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hi! I need some help!!!
I have to store some datas(picture files)in the path and when harddisk is full i need to overwrite datas by replacing the old datas first!
How can i implement this program ??
thx
|
|
|
|
|
peaceziz wrote: i need to overwrite datas by replacing the old datas first
This automatically implies that you need some sort of mechanism that would maintain file creation order. My suggestion is that you ought to have a data table stored on a local database (SqlExpress is MORE than adequate) where you can retrieve the file names/paths in order and delete as necessary.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
i am using ASP.net, C# anD SQL Server2005,in the following query:
string q = "SELECT collapsed_building.b_name,collapsed_building.b_desc FROM collapsed_building WHERE collapsed_building.b_name LIKE '" + crimewithdate.text2 + "' ";
I WANT TO USE % AFTER THE KEYWORD like SO THAT ALL THE BUILDING NAMES WHICH MATCH THE VALUE ENTERED BY THE USER ARE DISPLAYED
WHEN I WRITE (LIKE '" + %crimewithdate.text2 %+ "'), IT GIVES ERROR, WHAT WILL BE THE CORRECT SENTAX
|
|
|
|
|
(LIKE '%" + crimewithdate.text2 + "%')
|
|
|
|
|
J4amieC wrote: (LIKE '%" + crimewithdate.text2 + "%')
Don't encourage SQL Injection Attackable code, please.
|
|
|
|
|
I didnt encourage it, I simply corrected his mistake. Frankly if the OP has this wrong then he's going to be bafffled by terms that he doesnt understand.
Im 100% with you on the Sql Injection thing, but there is learning to walk before one can run.
|
|
|
|
|
J4amieC wrote: there is learning to walk before one can run.
I teach a basic C# training course. I actually threw out the materials I'd been given on the subject of databases and rewrote it. I ensure that at no time is anyone encouraged to inject values and I go directly to parameterised queries. So far with good results.
However, you might be right. If they already have the bad habit it might make it more difficult to break.
|
|
|
|
|
|
Im glad it worked. Now please heed the warnings below about Sql Injection attacks. IT IS IMPORTANT!
|
|
|
|
|
<br />
string qQuery = "SELECT b_name,b_desc" + <br />
" FROM collapsed_building" +<br />
" WHERE b_name = '" + crimewithdate.text2 + "' ";<br />
maybe u should ty = it always work
(just like an if)
p.s : yuo do not need to write "collapsed_building." as a prefix....
Have Fun
Never forget it
|
|
|
|
|
half-life wrote: " WHERE b_name = '" + crimewithdate.text2 + "' ";
Please don't encourage SQL Injection Attackable code.
|
|
|
|
|
Colin Angus Mackay wrote: Please don't encourage SQL Injection Attackable code.
Can u elaborate please?
i decided not to take "Athics and Hacking" course and instead i took
"advanced algorithms" in university
Have Fun
Never forget it
|
|
|
|
|
|
THANKS
vary infomative
Have Fun
Never forget it
|
|
|
|
|
Please don't do this. You leave your code wide open to Sql Injection Attacks. Instead, consider using the techniques described here[^]. You'll end up a better developer for doing it.
|
|
|
|