|
yes and also what does DayOfWeek mean, do we have to set it to one of the 7 values?
Regards,
Sowmya Mulukutla,
UAB
|
|
|
|
|
|
Hi all,
I am currently evaluating SSL components from IPWorks to
implement https protocol for client-server communication.
But it is a bit expensive, do anyone have any experience on using it
or are there any other cheaper component for SSL communication ?
Thanks
|
|
|
|
|
Ok i don't know how unknown this method is...or if i'm the last one to find out how...but i did it!
the secret lies in this:
[
XmlInclude(typeof(ClassToSerialize)),
XmlInclude(typeof(AnotherClass))
]
public class SerializableArrayList : ArrayList
{}
it was apparent from the errormessages that the serializer was struggling to determine the types of the objects it was trying to serialize...so if i use this class as my arraylist, and do the xmlinclude on any type my arraylist will hold, then i could serialize it. (i don't think it'd be possible to do this if you don't know the types...without making your own xml serializer)
This is what the serialized xml looks like. Notice the "AnotherClass"...this is the contents of an arraylist! and both serialization and deserialization works. Only thing i wish i could do is get rid of that anyType thing thats all over the place...if anyone knows how let me know...if anyone wants more code let me know...if you think this is good enough to be a article let me know :P
note: i had to double up on the xml braces, cause codeproject considers them page formating
<>
<<arrayofanytype xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">>
<<anytype xsi:type="ClassToSerialize">>
<<age>>3<>
<<name>>hi<>
<>
<<anytype xsi:type="ClassToSerialize">>
<<age>>4<>
<<name>>hi<>
<>
<<anytype xsi:type="ClassToSerialize">>
<<age>>5<>
<<name>>hi<>
<>
<<anytype xsi:type="AnotherClass">>
<<age>>666<>
<>
<<anytype xsi:type="ClassToSerialize">>
<<age>>6<>
<<name>>hi<>
<>
<>
|
|
|
|
|
Hi all,
Is it possible to write a SQL to join two tables from two different
databases ? Is this a common operation for business applications ?
If not, then is it not a good practice to split the stuff into different databases ? My case is like that : I have a central database to record
the meta information of all objects from different applications, and also
have a seperate database for each single application to store the detail of the objects. But when I search for objects according to some criteria,
then I need to have join SQL over two different databases(the central database and the application detail database).
Thanks
|
|
|
|
|
This is really a topic for the database forum.
When you repost this question there, you may want to provide some more detail about what you're doing, e.g.:
1. What kind of database are you using (SQL Server, MS Acess, MySQL, or ??)?
2. What you mean by "separate database" - do you mean an actual separate physical database instance, or just separate tables in the same schema?
Short answer: Yes, it is possible to join tables from 2 or more distinct database instances. The syntax varies from platform to platform. Without knowing why your data is arrayed as it is, I can't say whether your arrangement is an example of "good practice", although in my experience joining databases is rare.
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hi turbochimp,
Thanks for your reply.
The database I used is MS SQL CE on pocket pc device. And the two databases are on seperate physical database instances on the same device.
Could you point me to some reference for the syntax on MSSQL server or MSSQL CE(i think they are more or less the same) ?
My case is that I have several applications(each application has its own database instance) runnig together and they shared some common schema in a central database, so I need to join the central database and the application database for retrieving.
|
|
|
|
|
In Windows Forms the ListBox class has a GetItemText method, but lacks a GetItemValue method. How to retrieve the associated value of any specified item? There is a SelectedValue property. That does not work for me because I need to get the value for any item without changing the selection of the listbox.
Actually I was using the checkedListBox class. At a certain point in the program I want to get the associated values for the items the user put a check mark on.
Thanks for your help
|
|
|
|
|
if I have event jump and I have blobs that link to it can I use the event to get links to the blobs how, and yes I think the event holds the refs some how.
|
|
|
|
|
See this code:
string msg = "My name is ABC, hello there";
MessageBox.Show(msg);
Now I would like to add a parammeter to msg so that I can change the name, for example
string msg = "My name is {0}, hello there";
I don't like the following way for some reasons:
string msg1 = "My name is ";
string msg2 = ", hello there";
string name = "ABC";
then
MessageBox.Show(msg1 + name + msg2);
But I don't know how to do it.
|
|
|
|
|
String name = "ABC";
String msg = String.Format("My name is {0}, hello there",name);
msgBox.Show(msg);
Anger is the most impotent of passions. It effects nothing it goes about, and hurts the one who is possessed by it more than the one against whom it is directed.
Carl Sandburg
|
|
|
|
|
Hi,
I am installing some softwares to Windows 2003. Those softwares, after being installed, will add some COM+ components to COM+ Application under Component Services. Now I just want to write a piece of code to read the names of COM+ components that have just been added.
Can u guys give me some hints?
Thanks
|
|
|
|
|
Hai,
Below is the code i saw @
http://support.microsoft.com/default.aspx?scid=kb;en-us;301240.
Pl go tho' the ex & ans my qns
every thing is fine but sql connection path iam having doubt. actually iam using sql server 2000. in pubs database i have run the below given code.
conn = new SqlConnection( "server=localhost;Integrated Security=SSPI;database=pubs" );
my qn is wht should my connection path should be. directly windows based login iam using for sql server.
Think u got my qns . pl ans
chand
Create an ASP.NET Application Using C# .NET
1. Open Visual Studio .NET.
2. Create a new ASP.NET Web application, and specify the name and location.
back to the top
Configure the Security Settings in the Web.config File
This section demonstrates how to add and modify the <authentication> and <authorization> configuration sections to configure the ASP.NET application to use forms-based authentication. 1. In Solution Explorer, open the Web.config file.
2. Change the authentication mode to Forms.
3. Insert the <forms> tag, and fill the appropriate attributes. (For more information about these attributes, refer to the MSDN documentation or the QuickStart documentation that is listed in the REFERENCES section.) Copy the following code, and then click Paste as HTML on the Edit menu to paste the code in the <authentication> section of the file:
<authentication mode="Forms">
<forms name=".ASPXFORMSDEMO" loginurl="logon.aspx"
="" protection="All" path="/" timeout="30">
4. Deny access to the anonymous user in the <authorization> section as follows:
<authorization>
<deny users="?">
<allow users="*">
back to the top
Create a Sample Database Table to Store Users Details
This section demonstrates how to create a sample database to store the user name, password, and role for the users. You need the role column if you want to store user roles in the database and implement role-based security. 1. On the Start menu, click Run, and then type notepad to open Notepad.
2. Highlight the following SQL script code, right-click the code, and then click Copy. In Notepad, click Paste on the Edit menu to paste the following code:
if exists (select * from sysobjects where id =
object_id(N'[dbo].[Users]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Users]
GO
CREATE TABLE [dbo].[Users] (
[uname] [varchar] (15) NOT NULL ,
[Pwd] [varchar] (25) NOT NULL ,
[userRole] [varchar] (25) NOT NULL ,
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Users] WITH NOCHECK ADD
CONSTRAINT [PK_Users] PRIMARY KEY NONCLUSTERED
(
[uname]
) ON [PRIMARY]
GO
INSERT INTO Users values('user1','user1','Manager')
INSERT INTO Users values('user2','user2','Admin')
INSERT INTO Users values('user3','user3','User')
GO
3. Save the file as Users.sql.
4. On the Microsoft SQL Server computer, open Users.sql in Query Analyzer. From the list of databases, click pubs, and run the script. This creates a sample users table and populates the table in the Pubs database to be used with this sample application.
back to the top
Create a Logon.aspx Page
1. Add a new Web Form to the project named Logon.aspx.
2. Open the Logon.aspx page in the editor, and switch to HTML view.
3. Copy the following code, and use the Paste as HTML option on the Edit menu to insert the code between the tags:
Logon Page
Email: | | <asp:requiredfieldvalidator controltovalidate="txtUserName"
="" display="Static" errormessage="*" runat="server" id="vUserName"> | Password: | | <asp:requiredfieldvalidator controltovalidate="txtUserPass"
="" display="Static" errormessage="*" runat="server" id="vUserPass">
| Persistent Cookie: | <asp:checkbox id="chkPersistCookie" runat="server" autopostback="false"> | |
<asp:label id="lblMsg" forecolor="red" font-name="Verdana" font-size="10" runat="server">
This Web Form is used to present a logon form to users so that they can provide their user name and password to log on to the application.
4. Switch to Design view, and save the page.
back to the top
Code the Event Handler So That It Validates the User Credentials
This section presents the code that is placed in the code-behind page (Logon.aspx.cs). 1. Double-click Logon to open the Logon.aspx.cs file.
2. Import the required namespaces in the code-behind file:
using System.Data.SqlClient;
using System.Web.Security;
3. Create a ValidateUser function to validate the user credentials by looking in the database. (Make sure that you change the Connection string to point to your database).
private bool ValidateUser( string userName, string passWord )
{
SqlConnection conn;
SqlCommand cmd;
string lookupPassword = null;
// Check for invalid userName.
// userName must not be null and must be between 1 and 15 characters.
if ( ( null == userName ) || ( 0 == userName.Length ) || ( userName.Length > 15 ) )
{
System.Diagnostics.Trace.WriteLine( "[ValidateUser] Input validation of userName failed." );
return false;
}
// Check for invalid passWord.
// passWord must not be null and must be between 1 and 25 characters.
if ( ( null == passWord ) || ( 0 == passWord.Length ) || ( passWord.Length > 25 ) )
{
System.Diagnostics.Trace.WriteLine( "[ValidateUser] Input validation of passWord failed." );
return false;
}
try
{
// Consult with your SQL Server administrator for an appropriate connection
// string to use to connect to your local SQL Server.
conn = new SqlConnection( "server=localhost;Integrated Security=SSPI;database=pubs" );
conn.Open();
// Create SqlCommand to select pwd field from users table given supplied userName.
cmd = new SqlCommand( "Select pwd from users where uname=@userName", conn );
cmd.Parameters.Add( "@userName", SqlDbType.VarChar, 25 );
cmd.Parameters["@userName"].Value = userName;
// Execute command and fetch pwd field into lookupPassword string.
lookupPassword = (string) cmd.ExecuteScalar();
// Cleanup command and connection objects.
cmd.Dispose();
conn.Dispose();
}
catch ( Exception ex )
{
// Add error handling here for debugging.
// This error message should not be sent back to the caller.
System.Diagnostics.Trace.WriteLine( "[ValidateUser] Exception " + ex.Message );
}
// If no password found, return false.
if ( null == lookupPassword )
{
// You could write failed login attempts here to event log for additional security.
return false;
}
// Compare lookupPassword and input passWord, using a case-sensitive comparison.
return ( 0 == string.Compare( lookupPassword, passWord, false ) );
}
4. You can use one of two methods to generate the forms authentication cookie and redirect the user to an appropriate page in the cmdLogin_ServerClick event. Sample code is provided for both scenarios. Use either of them according to your requirement. • Call the RedirectFromLoginPage method to automatically generate the forms authentication cookie and redirect the user to an appropriate page in the cmdLogin_ServerClick event:
private void cmdLogin_ServerClick(object sender, System.EventArgs e)
{
if (ValidateUser(txtUserName.Value,txtUserPass.Value) )
FormsAuthentication.RedirectFromLoginPage(txtUserName.Value,
chkPersistCookie.Checked);
else
Response.Redirect("logon.aspx", true);
}
• Generate the authentication ticket, encrypt it, create a cookie, add it to the response, and redirect the user. This gives you more control in how you create the cookie. You can also include custom data along with the FormsAuthenticationTicket in this case.
private void cmdLogin_ServerClick(object sender, System.EventArgs e)
{
if (ValidateUser(txtUserName.Value,txtUserPass.Value) )
{
FormsAuthenticationTicket tkt;
string cookiestr;
HttpCookie ck;
tkt = new FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now,
DateTime.Now.AddMinutes(30), chkPersistCookie.Checked, "your custom data");
cookiestr = FormsAuthentication.Encrypt(tkt);
ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
if (chkPersistCookie.Checked)
ck.Expires=tkt.Expiration;
ck.Path = FormsAuthentication.FormsCookiePath;
Response.Cookies.Add(ck);
string strRedirect;
strRedirect = Request["ReturnUrl"];
if (strRedirect==null)
strRedirect = "default.aspx";
Response.Redirect(strRedirect, true);
}
else
Response.Redirect("logon.aspx", true);
}
5. Make sure that the following code is added to the InitializeComponent method in the code that the Web Form Designer generates:
this.cmdLogin.ServerClick += new System.EventHandler(this.cmdLogin_ServerClick);
back to the top
Create a Default.aspx Page
This section creates a test page to which users are redirected after they authenticate. If users browse to this page without first logging on to the application, they are redirected to the logon page. 1. Rename the existing WebForm1.aspx page as Default.aspx, and open it in the editor.
2. Switch to HTML view, and copy the following code between the tags:
This button is used to log off the forms authentication session.
3. Switch to Design view, and save the page.
4. Import the required namespaces in the code-behind file:
using System.Web.Security;
5. Double-click SignOut to open the code-behind page (Default.aspx.cs), and copy the following code in the cmdSignOut_ServerClick event handler:
private void cmdSignOut_ServerClick(object sender, System.EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect("logon.aspx", true);
}
6. Make sure that the following code is added to the InitializeComponent method in the code that the Web Form Designer generates:
this.cmdSignOut.ServerClick += new System.EventHandler(this.cmdSignOut_ServerClick);
7. Save and compile the project. You can now use the application.
back to the top
Additional Notes
• You may want to store passwords securely in a database. You can use the FormsAuthentication class utility function named HashPasswordForStoringInConfigFile to encrypt the passwords before you store them in the database or configuration file.
• You may want to store the SQL connection information in the configuration file (Web.config) so that you can easily modify it if necessary.
• You may consider adding code to prevent hackers who try to use different combinations of passwords from logging on. For example, you can include logic that accepts only two or three logon attempts. If the user cannot log on in a certain number of attempts, you may want to set a flag in the database to not allow that user to log on until that user re-enables his or her account by visiting a different page or by calling your support line. In addition, you should add appropriate error handling wherever necessary.
• Because the user is identified based on the authentication cookie, you may want to use Secure Sockets Layer (SSL) on this application so that no one can deceive the authentication cookie and any other valuable information that is being transmitted.
• Forms-based authentication requires that your client accept or enable cookies on their browser.
• The timeout parameter of the <authentication> configuration section controls the interval at which the authentication cookie is regenerated. You can choose a value that provides better performance and security.
• Certain intermediary proxies and caches on the Internet may cache Web server responses that contain Set-Cookie headers, which are then returned to a different user. Because forms-based authentication uses a cookie to authenticate users, this can cause users to accidentally (or intentionally) impersonate another user by receiving a cookie from an intermediary proxy or cache that was not originally intended for them. The following article explains how to combat
|
|
|
|
|
Hi!
I have a ListBox and I can get the selectedvalue. This selectedvalue is an int ID from an Access table. I have also checked the datatype by: textBox2.Text=ltbxLeft.SelectedValue.GetType().ToString(); It shows: System.Int32 .
My problem is that I cann't convert this ltbxLeft.SelectedValue into an integer. such as: int id=int.Parse(ltbxLeft.SelectedValue.ToString());
I got en error message saying: System.FormatException: Input string was not in a correct format.
Please help.
|
|
|
|
|
There is another property called SelectedIndex that does this for you. If you have object "o"...
"o.SelectedItem" and "o.Items[o.SelectedIndex]" both refer to the same object in the collection.
|
|
|
|
|
Thanks for your reply.
This is a Windows Forms application.
I use "ltbxLeft.DisplayMember" to display company name, use "ltbxLeft.ValueMember" to get the ID of the company:
ltbxLeft.DataSource = this.dataSet.Tables[tableName];
ltbxLeft.DisplayMember = columnName;
ltbxLeft.ValueMember = columnID;
By calling this method: "private void ltbxLeft_SelectedValueChanged(object sender, System.EventArgs e)", I can get:
ltbxLeft.SelectedIndex, ltbxLeft.SelectedValue, and ltbxLeft.SelectedItem
Everything works just fine, except that I cann't convert the ltbxLeft.SelectedValue, (which is an integer/the company ID in the table), into an integer, by whatever means (int.Parse; Convert.Int32,.....).
ltbxLeft.SelectedIndex gives me the number of the clicked listbox item (0,1,2...);
ltbxLeft.SelectedItem gives me the company name (by using dr = (DataRowView)(ltbxLeft.SelectedItem) to get it).
I can also get a string from ltbxLeft.SelectedValue.ToString() and display it in a textbox.
But I cann't convert this string into integer.
I have read Microsoft's example on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistcontrolclassselectedvaluechangedtopic.asp
which is about "ListControl.SelectedValueChanged Event". I have run the example, tried to modify the code and tried to convert the string in the example. I got the same problem!
Jeff Levinson wrote the following in DotNetMonster (http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-general/762/ListBox-Problem).
I think he is right. But I donn't know how to use thte CType. I got a namespace problem with Ctype.
Jeff Levinson------------
The key thing to remember in .NET is that combo and list
boxes do not store simple values, they store types. So
what you've done in this situation is you've bound a
dataset or a datatable to the listbox. You've set it up
to display one value by setting the DisplayMember
property. At this point you can do two things:
1. Set the ValueMember property (and use the
Listbox.SelectedValue property to retrieve the
information which returns a discreet value) or
2. Perform a ctype on the selected item to convert it to
a datarow and then extract the value you want.
Option 2 is more flexible, but Option 1 is a faster
operation.
|
|
|
|
|
Iam doing this for a combo
int nExpMonthIndex =
Convert.ToInt32(cmbExpMonth_ACL.SelectedValue.ToString());
The same thing can be applied to list box.
Hope this helps.
saleem
|
|
|
|
|
Thanks for your help. But it doesn't work for me.
I have tried exactly the same: int id= Convert.ToInt32(ltbxLeft.SelectedValue.ToString()).
But I got en error:
System.FormatException: Input string was not in a correct format.
If I use textBox1.Text = ltbxLeft.SelectedValue.ToString(), then I can have a string value (for example 13).
But I cann't convert this string into en integer.
|
|
|
|
|
Is it possible to write a program in C# that will not compile for the .Net run time? I’m not sure if this question is clear, let me try again. C++, depending on the compiler lets you compile to many platforms is the same true for C# and if so can anyone recommend a compiler other than VS?
Thanks
Ron
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
No. All of the managed languages (C#, VB.NET, J#, ...) are compiled into Intermediate Language, or IL, not machine code! When launched, the application is compiled into native machine code by the CLR's JIT compiler the first time that it is needed. So, no, C# can't run without the .NET Framework.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Using NGen.exe utility from .NET Framework SDK you can compile whole assemble into into processor native language and save the result in a file. CLR detects already compiled code and runs the application without launching JIT-debugger.
adocoder.
|
|
|
|
|
That’s what I was afraid of. Thanks a lot for you quick responses
Time to dust off the ol' C++ books
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
There is an alternative compiler - Borland C#Builder.
|
|
|
|
|
Hi all!
I need to make a form with a DataGrid, that would represent a two-dimensional matrix. I woul look like this DataGrid[Account,Month] = Sum. I have a fixed collection of accounts. The user enters a period [StartMonth;FinishMonth] and the Grid calculates the sum of money, spent for each expense Account in each Month and represents it in a form of a matrix.
The problem is that we don't know the number of columns (months in the period) before we run the program. That's why we can't determine the structure of the cless that would represent a row for our Grid. The MAIN PROBLEM is: How can I create a Grid where the number of columns is calculated at runtime? What class should I use as a DataSource for my DataGrid? And what kind of element (class) should I use to supply data for this DataSource?
Thank you in advance for your help.
adocoder.
|
|
|
|
|
Hi,
I have used a colormatrix before to convert an image into black and white (code included), I now want to adapt this code so that i can convert the image to sepia, does anyone know the colour quantities for this?
ColorMatrix cm = new ColorMatrix(new float[][]{ new float[]{0.3f,0.3f,0.3f,0,0},
new float[]{0.59f,0.59f,0.59f,0,0},
new float[]{0.11f,0.11f,0.11f,0,0},
new float[]{0,0,0,1,0,0},
new float[]{0,0,0,0,1,0},
new float[]{0,0,0,0,0,1}});
Any help would be great,
Thanks
|
|
|
|
|