|
Just an idea, what if you have a collection of objects, and everytime serialize and deserialize the whole collection? That way, you could in code add, remove, or change the items, and serialization would be automatic.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hello,
I created an xml file and created a class matching that file using xsd.exe tool. Im inserting data from the file to an instance of the class using serialization:Instance=(casting)XmlSerializer.Deserialize(FileStream),
and Im saving changes to the xml file:
XmlSerializer.Serialize(FileStream,Instance).
My problem is that sometimes when storing data from the instance of the class to the file destroys the fomat of the xml file and the file can no longer load unless I change it back. The format is destroyed by adding xml tags that belong to the file but not in the right place. This happens when I use the folderBrowserDialog to change one of the parameters of the instance and only on specific chosen directory of the dialog.
|
|
|
|
|
hi folks,
i am looking for some ideas as how i could go about adding icons to a context menu ??? For my purpose, my context menu looks at a particular dir and appends all available files to the menu. Each file that gets appended to the context menu, the associate application icon also gets appended on the left handside of the filename. I know how to extract the file icons. But as how to append each of the icons to it's respective file in the context menu i have no idea about.
One idea I had was to use a delgate to invoke the OnDrawItem Event handler each time the context menu is invoked ? I havent attempted to do this yet. Now is this a possible solution or are there alternatives i dont know about ??
i would appreciate any feedback.
thanks
|
|
|
|
|
well i had received an email from an anonymous user at CP asking me if i had come up with a solution to my problem. Well yes and no is the response. No because i couldnt work out the delegate aspect of the solution. Yes because i saw another article in which the author used main menu and ownderdrawn method to append the icons.
The article is here :
http://www.csharphelp.com/archives/archive282.html
The article did provide me with an idea of how to tackle my problem. However, I have had other things to do so I havent had much time to try it out. If I have some time over the weekend or next week I will post back my solution.
so hope this helps.
cheers
|
|
|
|
|
I make a simple search like in database like this
sql="SELECT * FROM "+tableName+
" WHERE "+this.cbColumn.Text+
" LIKE '*"+this.tbKeyword.Text+"*'";
And I bind to datagrid -> no result value display
But when i test in Access Query with this sql string. It showed the result.
Can anybody help me ! Thankz for reading.;)
|
|
|
|
|
Two things:
1. The wildcard character in SQL is % , not * like in Windows or Access.
2. If you are accessing the database with that SQL string, use parameterized queries. By concatenating strings, you are subject to SQL injection attacks. See the Parameters property of the SqlCommand class.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Luis Alonso Ramos wrote:
By concatenating strings, you are subject to SQL injection attacks.
Looks like I have to be quick around here to point out security problems in SQL!
However, if you look again you will see that the table name is one of the things he is injecting and that cannot be inserted in to a parameter without some extra work and some compromise.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
Colin Angus Mackay wrote:
Looks like I have to be quick around here to point out security problems in SQL!
Yeah, I'm working hard on it!!
Colin Angus Mackay wrote:
you will see that the table name is one of the things he is injecting and that cannot be inserted in to a parameter
I hadn't noticed it, but now I read your answer, and all I can say is cool!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
As Luis said the wildcard in SQL Server (and most other database systems) is the % percent sign.
Also, he mentioned that you should use parameterised queries, however in your case this is going to be more problematic as you are injecting the table and column names into the SQL statement - something that is not easily parameterised.
What I suggest is that you create a stored procedure for this and in the stored procedure accept the table and column name as parameters. You can then verify that these values are valid.
I have to admit that I couldn't figure it out in a single stage. So here is a safer solution that I present:
CREATE PROCEDURE dbo.BuildSelectStatement
@tableName sysname,
@columnName sysname
AS
-- First, check that the table exists
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = @tableName
AND TABLE_SCHEMA = 'dbo'
AND TABLE_TYPE = 'BASE TABLE')
BEGIN
SELECT '' AS result;
RETURN
END
-- Second, check that the column exists in the table
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @tableName
AND TABLE_SCHEMA = 'dbo'
AND COLUMN_NAME = @columnName)
BEGIN
SELECT '' AS result;
RETURN
END
-- Everything is fine, build the SQL Statement.
SELECT 'SELECT * FROM ['+@tableName+'] WHERE ['+@columnName+'] LIKE @comparison' AS result
GO
The above stored procedure will send back an empty string if the data is invalid, or a SQL Statement if the result is fine.
Then in your code you can write something like this:
SqlCommand buildSqlCmd = new SqlCommand("BuildSelectStatement", myConnection);
buildSqlCmd.CommandType = CommandType.StoredProcedure;
buildSqlCmd.Parmaters.Add("@tableName", tableName);
buildSqlCmd.Paramters.Add("@columnName", this.cbColumn.Text);
string sqlStatment = (string)buildSqlCmd.ExecuteScalar();
if (sqlStatment == "")
{
}
SqlCommand runQueryCmd = new SqlCommand(sqlStatement, myConnection);
runQueryCmd.Parameters.Add("@comparison",
string.Format("%{0}%", this.tbKeyword.Text));
SqlDataReader reader = runQueryCmd.ExecuteReader();
Does this help?
DISCLAIMER: I typed all this in directly, it has not been tested, there may be minor errors
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
Clearly and helpful.You're so nice.
Thankz for both of ur helps!
BlueDot
|
|
|
|
|
Hi all
I want to write a program that will read a text file as an unput. This file will contain some info for students, one student in one line. It might contain 60,000 to 500,000 lines.
Now the program shoul read each line and store the info. into the database.
My question is:
What is the fastest way for doing that?
inserting the data into the database must be through the program(not importing the data through the SQL Server or MS Access).
Would u help me please
|
|
|
|
|
First of all you will need to open a connection to the database. Depending on which db you want to write to choose one of the providers coming with the framework (OleDb, ODBC...). If you need it fast you'll probably have to test them.
If its possible I would define a stored procedure in the database. Otherwise you will have to make a parameterized query. Once this is done the reading can begin.
You will now need a FileStream to open the file and read it line by line. Depending on the format you will have to split each line some way and fill in the parameters to your query. Execute it and go fopr the next line.
Thats it.
|
|
|
|
|
Thanks
But, would u tell me more about parameterized query and give me some resources or examples.
And another Q, do u prefer to insert the data line by line or first read as much as I can from the file and the insert them together.
|
|
|
|
|
1. Have a look here. Its in VB.Net and originally meant for ASP. But the same techniques apply for C# windows applications. The sample there could give you a good start. As you want to load data into the database and not read the only really difference is that you will have to use ExecuteQuery instead of ExecuteReader.
2. When using parameterized queries you will have to insert the data line by line. Thus there is no real reason to load more than line at a time into memory. In order to increase you could read your data in one thread (storing many lines in memory) and writing them to the database in another thread. This could improve performance in certain situations, but is also a bit advanced, so you probably should stick to the line by line handling.
|
|
|
|
|
If you are going to work with SQL Server The fastest way will be to use DTS.
Uri
|
|
|
|
|
|
DTS is a part of the SQL Server and it states for: Data Transformation Services.
It is particularly handy when you want to perform a task of transferring a data from text files, excels or other databases. DTS will be significantly faster than other program under assumption that there is no special business logic for the data to be transferred (Conversion of data isn’t considered to be a special business logic and can be easily done by the DTS).
Hope it helps,
|
|
|
|
|
hi,
i'm a developer in a consultant company. They asked me do a ( blog Page ) in ASP.net but the idea of programming blogs in dot net is new to me. so can any body helps me and guide me how to do this? any wizards ? code examples ? any thing any thing that can helps me thanks ..
|
|
|
|
|
*hides a smile* hehe, it's not that difficult (although this depends on what you exactly want) So let me ask you: What exactly do you want to be in the blogsystem?
Here's an example of an open source PHP blogsystem. http://www.bblog.com/[^]
There's also a .NET blogging system that has a workspace on gotdotnet
http://www.gotdotnet.com/workspaces/workspace.aspx?ID=E99FCCB3-1A8C-42B5-90EE-348F6B77C407[^]
All I can say is: Get a basic Idea and start working from there. If you know what you want, you can ask more specific questions on how to solve parts of the problem
WM.
What about weapons of mass-construction?
|
|
|
|
|
A blog is a pretty basic sort of site - what do you normally do there ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
Is it passible to overload a enum datatyp?
regards,
hasan
Mohamed Hasan is usally called as Hasan. He is very much interested in C++ programming . He slowly picking up .NET programming. He done his Bachler degree in Arumugam Pillai Seethai Ammal college Thiruppathur. and Master degree in MK university College.
Contact him at: hasansheik@hotmail.com
hasansheik@yahoo.co.in
hasansheik@lycos.com
|
|
|
|
|
Are you sure you know what overloading means?
No its not possible and I dont even know what exactly you mean
|
|
|
|
|
Overloading enums? Overloading applies to functions, defining functions with the same name but with different signatures.
Maybe you meant extending enums by deriving from them? Nope, that's not possible.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Which is much faster in retrieving data form sql or xml ?,
And what is the advantages of each ?
|
|
|
|
|
The question is somehow wrong.
XML is a way to format data so that they can easily be read in a standarized way. SQL is a language to retrieve data from databases. So they are targeting completely different things. There are even database where an SQL query works on or even returns XML.
The advantage of XML is that its a standarized way to format data and libraries exist for nearly every programming language to easily read them. Because it is generally file based and needs many string operations it is relatively slow (compared to other formats).
With SQL you have a language at hand where you describe what data you want to get from a datasource. The advantage is that about every database allows SQL queries and the syntax is nearly the same on all of them. But it doesnt provide any way to access the database. For that you'll need some libraries which transfer your commands to the database and retrieve the data so you can access it. In .Net this is done by various providers (e.g. for OleDb, ODBC, Oracle...). Depending on which one you choose this access is generally by far faster than XML (at least when it comes to large amounts of data).
|
|
|
|