|
Thanks Heath
I got your point
|
|
|
|
|
The bin (binaries) folder is the one you should be using. The obj folder is used to hold temp build files and for debugging purposes.
The bin folder has seperate directories for your build types and generally you want to build .pdb files with your release build in case you have to do any remote debugging.
|
|
|
|
|
Hi.. I'm currently doing a web design on the calendar using C# web application.I have created a calendar. I would like to ask that if i click the date on the calendar, can i retrieve the database?? I have tried several times and it seem like is not working. Below is my code, could anyone help me that if i missing on any parts?? Thanks!! My code:
.
.
.
using System.Data.SqlClient
private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
TBDate1.Text = CAL1.SelectedDate.ToLongDateString();
SqlConnection conn=new SqlConnection("put my connection string here");
string seldate = "Select * from Particulars where DateField = '" + TBDate1.Text + "'";
SqlDataAdapter DA = new SqlDataAdapter(seldate,sqlConnection1);
DataSet DS = new DataSet();
DA.Fill(DS);
DataTable DT = new DataTable();
DataGrid1.DataSource=DS.Tables[0].DefaultView;
DataGrid1.DataBind();
}
Thanks for your help..;)
Cheers!
|
|
|
|
|
First of all, never use string concatenation like that in SQL strings. All I have to do as an attacker is set the TBDate1.Text field (either in the page or via an HTTP GET or POST) to ' or 1=1; delete from Particulars; -- and your table is gone. With probing I could do worse, such as steal credit card information or other private information, etc. This is called a SQL injection attack and is one of the most overlooked vulnerabilities. Use parameterized queries using the SqlCommand.Parameters collection property.
That's also the answer to the problem here. Dates are typically surrounded by "#" (depending on the database management system) but using parameters eliminates having to know that:
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Particulars WHERE DateField = @Date";
cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = DateTime.Parse(TBDate1.Text);
Add some error-handling, though, since DateTime.Parse could fail if incorrectly formatted.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
I've declared an instance of a class in the startup page of my app
eg Car mycar = new Car()
and have assigned various attributes into it.
I would like to refer to the instance mycar in other pages (either in the aspx or .cs )
eg mycar.model
I'm getting The type or namespace name 'mycar' could not be found (are you missing a using directive or an assembly reference?)
What's the best way to declare the instance of this class to my other pages?
thanks,
John
|
|
|
|
|
Pages are executed in separate threads, such that an instance of one page is not persistent so one page can't access the variable of another. Store singleton class instances in your Application object in global.asax or use a singleton. There's many ways to do this. You can find more suggestions in the ASP.NET forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
thanks for your reply Heath,
Each user will have their own instance, with different properties - I assume a singleton is not appropriate?.
The class is declared in its own namespace.
Initially I referred to the class directly (rather than its instance) in other pages via the using 'namespace' entry. This worked, but each user overwrote the properties of the class!, hence of course I needed to use the class instance!.
I was hoping to reference the class instance in a similar way.
I may need to store the class instance in session (from the initial page), then retrieve it when needed.
thanks,
John
John
|
|
|
|
|
You only defined the class. An instance is created for each page request (even the same page in a different request, like after a post-back). This is crucial to how pages are executed in ASP.NET. If the object is to be stored per-user, store it in the Page.Session dictionary property instead. When the session expires the object will not be available. In you're using ASP.NET 2.0, look into the personalization feature. You can get an overview and read a tutorial at http://msdn.microsoft.com/library/en-us/dnvs05/html/person_fin.asp[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
just use the namespace and the class then u will get the object of your class.
eg if
namespace WinTest
{
class abc{
public test mytest = new mytest();
}
}
class test
{
public int i;
}
now in class2 u can get the object as follows
WinTest.abc.mytest.i;
hope it will help
|
|
|
|
|
thanks nbobby,
this looks just like what I'm after.
best regards,
John
John
|
|
|
|
|
Keep in mind that this is a different instance, not the same instance created in the other page. A class and a class instance (as you mentioned in your subject) are two different things. Classes can be referred to from anywhere so long as the assembly in which the class is defined can be loaded, and that the class is not inaccessible due to its accessibility modifier (like an internal class). To keep the same instance you need to keep the instance alive. For per-user instances you can use the Page.Session variable. See my other reply for more details.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath you r correct ... i cant access the value that i set for the object variable in the class2.
What does this mean ...
im creating the Windows application
|
|
|
|
|
In order to access an instance of a class you must access the instance itself. Being able to use the class doesn't mean anything (unless it's a singleton, which is accessed different depending on the context). In a Windows Forms appliation this is much different than an ASP.NET application, where each page (or other handled type) is short-lived and runs in a separate thread for only as long as the page is processed. Instances of pages are not kept alive like Windows Forms. To access an instance of a class (an object) within another form you must pass a reference to that object, or to the form in which the field or property that returns that object is accessible (public or internal).
Windows Forms appliations and ASP.NET web applications are very different from each other, regarding how they are executed. They even run within different CLR hosts. MSDN has lots of information about the execution models for both types of applications.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
very helpful info Heath,
thanks
(I'm using session!)
John
|
|
|
|
|
Thanks Heath
I used the same refernce pass in windows application
|
|
|
|
|
I enbaled the top most property of a child form to make it remain on the top of the application window, although not to my knowledge this set the form to be the top most of every other window as well, can anyone tell me how I can get the form to only remain on top the application window and now all the native XP windows. Thanks
Ruskin
|
|
|
|
|
dont use Top Most therefore set top most property to false, set the child form's Owner property.
say
ChildForm child = new ChildForm;
child.Owner = this;
"this" implies tie it to the parent form.
|
|
|
|
|
Thanks that helps a lot, but there is still a small problem.
Say I have a MDI container which can have several different windows within it. Say the main MDI window is 'A', it has a child window within it called 'B' and another child window called 'C'. Now window 'B' opens another small window 'D' which I want to be on top, but I only want it to be on top of 'B' and not on top of 'C', can i achieve that?
|
|
|
|
|
I don't think you can. If you created the form by itself, and set it's Owner property to A, it would always be above A. But if you want to do that for a MDI child on another MDI child, sorry but you can't.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
Yeah I had a look around, if a form is an MDI child, and that opens another window which you want on top of the mdi child which opened it and not any other mdi child, that is not possible
Is there any way around so we can simulate that behaviour?
|
|
|
|
|
Ruskin Dantra wrote: Is there any way around so we can simulate that behaviour?
I looked around at it a little bit, and no, I can't think of anyway to simulate it. MDI was just not designed to do that. Sorry!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
How to get a reference to string? I mean that I want to have 2 string objects, that both point to the same string in a memory
|
|
|
|
|
A System.String (string in C#) is a reference type, so the following are equal:
string a = "Hello, world!";
string b = a;
Console.WriteLine(object.ReferenceEquals(a, b)); Strings are immutable, however, so as soon as you change one string - which actualy returns a copy of the string with your changes - the references are not equal. It's also important to note that string equality (the == operator) is based on the content and not the reference.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I'm trying to plan abit of code for a space game and I've ground to a halt.
Here's a theory:
A Class called Object which might have some properties like Location.
Two other classes inherit this object, Planet and SpaceStation. And they their own methods and properties appropriately.
Simple so far.
Ok, so I want to create planets and spacestations and chuck them into a collection, I guess Universe.
so questions:
1) Does a class inserted into a collection always have to be exactly the same as the other existing in there?
2) If I loop through all the classes within the collection, how do I tell whether one class is a Planet or if its a SpaceStation?
Any response gratefully appreciated.
Andy
|
|
|
|
|
Avoid naming the class Object, or you will have to specify the full namespace every time you use it, as there is a class named Object in the System namespace.
You can either create a typed collection for objects of the base class, or use an untyped collection, like an ArrayList or a Hashtable. For a typed collection, you can use any member that you declared in the base class without type casting the objects. For an untyped collection, you have to type cast the objects to the base class or the specific class before using them.
To check the class of an object, you use the in operator:
if (anObject is Planet) {
((Planet)anObject).SomeMethod();
} else {
((SpaceStation)anObject).SomeOtherMethod();
}
---
b { font-weight: normal; }
|
|
|
|