|
Hi, Vikram.. Thanks for replying.. Actually, maybe what i explained is not very clear to you.. But actually, what i wants to do is that i've create a calendar and what i need to do now is that when i click on the date i've select it will show out the database of the user.. Is it clearer for you. As you've mention earlier on that i shouldn't write the ToLongDateString() if i using DateTime.ToString().. Can i ask you, then now how should i write the code so that it'll show out the database when i click on the date. Thanks!!
Cheers!
|
|
|
|
|
saddies wrote: what i need to do now is that when i click on the date i've select it will show out the database of the user
What do you mean by 'database of the user'?
Let's say you want to retrieve all the details of employees who joined on a certain date, from a table Employee. Assume that the user chose the date 01 Sept 2004, and that it is contained in the DateTime value userDate. Your query should look like:
string selectQuery = "SELECT * FROM Employees WHERE JoiningDate='" + userDate.ToString("yyyy-MM-dd") + "'";
Of course, the details will differ in your application, but you should get the general idea.
Cheers,
Vikram. "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
|
|
|
|
|
Well done, the OP was actually using paramaterized queries and you just taught him how to introduce Sql Injection attacks to his code.
|
|
|
|
|
Jamie, I took a look at your reply below and it's interesting - I didn't know that parameters are automatically converted at runtime. Thanks!
But what do you mean by 'introducing SQL injection attacks'?
Cheers,
Vikram. "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
|
|
|
|
|
|
Thanks, Jamie. Glad to have learnt something useful today.
Cheers,
Vikram. "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
|
|
|
|
|
Hi, I can see from your code that when a user selects a date, you display it to him apsolutely 100% perfectly!! It will be formatted according to HIS/HER windows settings
This line is perfect!
TBDate1.Text = CAL1.SelectedDate.ToLongDateString();
However, take 1 step backwards:
DateTime selectedDateTime = CAL1.SelectedDate;
Without the .ToLongDateString() call, you have a DateTime Object.
The only place you went wrong below is that you tried to parse the string back into a Date, which at best is unnecessary and at worst will not work.
SqlConnection conn=new SqlConnection("my connection string");
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Particulars WHERE DateField = @Date";
cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = DateTime.Parse(TBDate1.Text);
The beauty of parameters (especially date ones) is that the ADO.NET provider will take care of any conversion for you... so change the last line to:
cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = CAL1.SelectedDate;
simple, huh?
|
|
|
|
|
Hi,J4amieC.. Below is my code which i have changed.. But somehow when i run the program, the database does not show out when i click on the date. Is there's anything wrong or i still missing on some part??
DateTime selectedDateTime = CAL1.SelectedDate;
SqlConnection conn=new SqlConnection("my connection string");
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Particulars WHERE DateField = @Date";
cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = CAL1.SelectedDate;
Thanks for your help!!
Regards
|
|
|
|
|
I am now using Random r=new Random() to generate random number.
Now for debugging purpose, I want want my program to generate same random number every time i run it. I guess i need to use a fixed seed in order to do that. but i do not how. Can anyone please give me some suggestion?
Thanks
|
|
|
|
|
A quick search on MSDN:
public Random(int Seed);
Simply provide the same seed.
Cheers,
Vikram. "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
|
|
|
|
|
I like to use windows shell icons in my program as menuitem icons. How can i include those without extracting them first and then import as resource?
EG:
I have a file menu and would like to have a blank page icon next to the new file entry.
To learn to fly the hard way, you just have to jump and to forget to hit the ground. The rest comes with it.
|
|
|
|
|
Use a program like the free IrfanView to extract icon images out of the shell icon library file (shell32.dll).
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Bought a House!
Judah Himango
|
|
|
|
|
The question was, to do it without extracting them first.
Point is, that i have some example programs that do not have in included icons but show them in the menu. They aren't written in c# so maybe its something c# cant do, but i like to understand how it works.
Nothing is impossible, but to understand a woman.
|
|
|
|
|
Hi,
I am still new at C# and am coding an app that has tabs and on each tab is a treeview. I need to figure out which tab is selected and wich node on the treeview is selected for the current tab when the user clicks on certain menus.
I found a way to do it, but was wondering if there was an easier way.
TreeNode node;
string tabName = _tabs.SelectedTab.Text;
switch (tabName)
{
case "One" :
node = _tvwOne.SelectedNode;
break;
case "Two" :
node = _tvwTwo.SelectedNode;
break;
case "Three" :
node = _tvwThree.SelectedNode;
break;
}
Thanks in advance.
Sean
|
|
|
|
|
If you only have TreeView s on the tabs, you could use this code:
TreeView tv = ( TreeView ) tabControl1.SelectedTab.Controls[ 0 ];
TreeNode activeNode = tv.SelectedNode; Or, to get really terse:
TreeNode activeNode = ( ( TreeView ) tabControl1.SelectedTab.Controls[ 0 ] ).SelectedNode;
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
In reference to my previous post, you can use that code with TabPage s that have more than just the TreeView s on them. You just need to ensure that the TreeView is the FIRST control added to the TabPage .
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Thank you. That works great.
Sean
|
|
|
|
|
Happy to hear it. Keep on codin'!
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I have a binary data file saved as serialized object , when it is deserialized to datatable then binded to a datagrid , the user will make som changes to a record then save these changes back to the file , how can I save back the changed record ,do I have to serialize the all items each time when a one record updated , what is the right method to do so ,,, any help ;
thanx ........
|
|
|
|
|
|
leppie wrote: Yes, you have to 'overwrite' the old serialized object
Thank you, so what is the best way other than serializaion to deal with binary data files that been saved as blocks or records .
|
|
|
|
|
Hi, everyone, I'm new in this forum, I'm a question about if is posible when is run a program(update.exe) recall the program(update.exe), I'm desing a Update program but How can i close my update.exe when hava a new update of my exe and continue the process?
For your help thanks.
|
|
|
|
|
Search CodeProject or the web for "single instance application". There's some decent articles on CP regarding this, for example, here[^].
"Every technology has its detractors. I'm sure that somebody once stated that the pointy stick would never replace the fingernail as the fighting man's weapon of choice." Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Bought a House!
Judah Himango
|
|
|
|
|
Hi, I have a form that launches an external shockwave flash program and need to check, first, if the flash player is installed on the PC. Any ideas?
Thanks ahead!
radnix@hotmail.com
|
|
|
|
|
You check for the existence and validity of the HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ShockwaveFlash.ShockwaveFlash key and its subkeys.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|