|
Nadia Monalisa wrote: expose an Excel Spreadsheet like facility
That is rarely a good idea, it's not very user-friendly, but this may be one of those rare times, just be sure, ask potential users for their opinion.
|
|
|
|
|
You need some kind of mapper to map the data properly. After making the changes on the grid, get the currently available Person instances from grid's datasource and compare it against the list that you load from database. You will need some unique identifier on the Person type which can be used to find out the proper domain object. Given the two lists, you can do a diff and find out newly added, updated and deleted records.
Best wishes,
Navaneeth
|
|
|
|
|
Thanks for your reply.
Sounds like a lots of tasks, moreover maintenance can be nightmare if I keep changing my domain model and database table fields. I thought, if I implement INotifyPropertyChanged in my Business Object (Person Class) then, the .NET Framework can notify a data context about dirty rows automatically. I tried and that did not work. Looks like, I will have to compromise either Excel / Spreadsheet functionality or Decoupling of Presentation Layer + Data Access Layer (LINQ to SQL DataContext class)
|
|
|
|
|
Nadia Monalisa wrote: Sounds like a lots of tasks,
Not actually. You have all the information, you just need to match with proper objects. And finding diff, a single line LINQ can do it.
Best wishes,
Navaneeth
|
|
|
|
|
Thank you for showing the light. I will give a try. I just missed the idea about using LINQ to find the diff. now feeling easy
|
|
|
|
|
HOw about a couple of extra properties on your Person Class.
bool IsUpdated;
bool IsDeleted;
Your grid needs to be filtered to omit the IsDeleted items (or just highlight them in some way so the user can change their minds)
Set the IsUpdated when anything is, erm, updated.
Then your DAL just updates where IsUpated, and deletes where IsDeleted.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Thank you for your reply. Actually I intended to use a boolean property 'IsDirty' for a dirty row. But, In order to set this 'IsDirty' property, I will need to write code which may not look clean and maintainable. I may need to handle some events of the GridView to set this IsDirty property. It can be more messy if i want to maintain IsDeleted property as well.
But, I thought, INotifyPropertyChanged interface was invented for solving this problem. Am I wrong ? When I see some demo videos about Silverlight / WPF, I see the instructor is implementing INotifyPropertyChanged interface on business objects and tracking is being taken care by the framework.
Moreover, when working with Silverlight, I am forced to use Business Objects instead of direct database access, as Silverlight is a client side tech. So, the framwork is offering solution for Silverlight !
Am I missing anything about it ?
|
|
|
|
|
Ok, i am having a really harsh times trying to figure this out. Basically, i am trying to create a simple database - really simple task but i am failing over and over again and all this MSSQL thing seems to me like some kind of dark black evil magic
So here is the scenario (OS is Vista and server is sqlexpres 2005). First off, to eliminate error 5 (access denied) for it to be able to save .mdf and .ldf files in my application current directory, i had to launch mssql server under Local System account (it was running as Network Service first) - i got no idea if this is correct fix though. Ok, here we go. Here is my code for creating new DB:
private void CreateDatabase(String ConnectionString, String Query)
{
if (String.IsNullOrEmpty(ConnectionString) ||
String.IsNullOrEmpty(Query))
{
return;
}
else
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
try
{
if (conn.State != ConnectionState.Open)
conn.Open();
SqlCommand cmd = new SqlCommand(Query, conn);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show("ERROR: " + ex.Message);
}
finally
{
conn.Close();
}
}
}
}
Connection string is simple: server = CSRSS-PC\SQLEXPRESS, Integrated Security = True, database = master.
I am using windows auth, not sqlserver auth. And query is simple too:
String sql = "CREATE DATABASE aaaaa ON PRIMARY"
+"(Name=aaaaa_DB, filename = 'C:\\Users\\csrss\\Documents\\Visual Studio 2008\\Projects\\mssql\\mssql\\bin\\Debug\\aaaaa.mdf', size=3,"
+"maxsize=5, filegrowth=10%)log on"
+"(name=aaaaa_log, filename='C:\\Users\\csrss\\Documents\\Visual Studio 2008\\Projects\\mssql\\mssql\\bin\\Debug\\aaaaa_log.ldf',size=3,"
+"maxsize=20,filegrowth=1)";
While server was running as Network Service - this code was returning this error 5 (access denied).
Now, when i have restarted server as well as writer as well as reader under Local System account - now it can create files in my app dir, but here goes next thing. I got this button for running the above code. So i click it and observe. Indeed, these 2 files (db and log) suddenly appeared in folder, but application stopped responding. Ok, i am waiting. After, like, 5 seconds, db and log files disappeared, and application gives me this exception:
Cannot obtain exclusive lock on 'model', try again later. And the funniest thing, btw, here is a function i wrote for fetching databases:
public static String[] GetDatabases(String ConnectionString, Boolean extra)
{
List<String> l = new List<string>();
String[] output = null;
if (String.IsNullOrEmpty(ConnectionString))
{
return new String[] { "ERROR: Empty connection string!" };
}
else
{
DataTable dbs = null;
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
if (conn.State != ConnectionState.Open) conn.Open();
try
{
dbs = conn.GetSchema(extra ? "tables" : "databases");
}
catch (Exception ex)
{
conn.Close();
return new String[] { ex.Message };
}
finally
{
conn.Close();
}
foreach (DataRow dr in dbs.Rows)
{
l.Add(dr[extra ? "table_name" : "database_name"].ToString());
}
}
output = l.ToArray();
}
return output;
}
So, now if first i will not call a function for obtaining databases, and i call a function for creation of new database, i got exception that server is unreachable, or there is no sql server running on my PC, or something like that. Only after i call "GetDatabases", i can call "CreateDatabase", which gives me exception that it cannot obtain lock and i got no other connections to sql server so what is wrong with this lock? What is wrong with this code? This is some kind of an horror working with this mssql thing
Thanks for any help in advance.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Ok, solved it myself. The first issue appeared because i forgot to initialize connection string. Whatever.
Next issue, with this exclusive lock, you will never find such explanation in google, lol.
So, the answer is so simple, if you bounded a datagridview to sql table (or in reverse) there appears an extra something, which is called .Net sql client data provider, and this beautiful data provider locks database model. How i love all these C# adapters and providers, gosh...
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
As far as your problems in using SqlExpress as a Network Service are concerned, take a look at this[^] thread on MSDN.Social. Scroll down to the answer from Tommy123456 .
I also suspect that your database creation problems might also be caused by a 'permissions' problem (on the file system, this time), although as I am still running XP I cannot be more explicit about Vista.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
Thanks, that was informative. However, first issue is directory access related - Network Service has the lowest rights (in case of writing data anywhere) and i dont have time to mess with configuration and granting access to it everywhere, and it is not that important.
Second issue was that exactly what i have pointed out - i forgot that i have bound a mssql table to a dataset, basically, this query solved the issue:
select spid ,PROGRAM_NAME from master..sysprocesses where DB_NAME(dbid) = 'model'
so when its bound, sql data provider locks database; if database 'model' locked - new database cannot be created, as you know. Kids stuff, yet sometimes mind goes blur and you just stuck with it. Anyway, solved.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Hi all,
i need to sort a listview based on the item tag property (as a category)
in fact, the listview is populated with a folder content from windows explorer.
when i click on the column header, i need to sort by name the folders and the after the files
Example :
the desired result
MyFolder
YourFolder
MyFile
YourFile
instead of
MyFile
MyFolder
YourFile
YourFolder
thanks for any idea, snippet code or a link
best regards
Fady Sayegh
|
|
|
|
|
The ListView class has, oh surprise, a Sort method. It offers a default sorting order, however it also provides a custom sorting order. MSDN holds the essential information, and one of my articles (see link in sig) deals with sorting in general, it does not mention ListView in particular.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi Luc,
thanks for your quick answer.
can you please provide me the link to your article.
sorry but i have clicked on the link [My Articles] but i didn't find any article about sorting issues
can you please redirect me to the right url.
thanks again for your help
Best regards
Fady Sayegh
|
|
|
|
|
just enter sorting and click the find button, that should do it.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Well your title "Sorting a Collection" only gives a small clue.
I must get a clever new signature for 2011.
|
|
|
|
|
Yeah, I spend most of my time searching for catchy, unexpected and mysterious titles, and yet I often fail at it.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Seriously?
see here[^]
There has always been a sort in list view.
It is amazing that you are asking such a fundamental question.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
In addition to Dalek Dave answer I am suggesting you to read these article [ Link1[^] and Link2[^] ] for more information
|
|
|
|
|
Hallo
I have two tables, let's say one Customers and one Orders, joined by CustomerID.
I represented each one by a datatable of its own in a dataset, and I created a DataRelation.
I would like to use them as datasource for one single BindingSource: is it possible?
|
|
|
|
|
I suppose it depends on the control. DataGrid(View)s can do that sort of thing, but it's generally not a good thing to use. I prefer a TreeView.
What would you want the control to do?
|
|
|
|
|
Hallo, thanks for reply.
The control will display data from the bindingsource and permit editing.
I'm currently using a dgv, but I'm actually aiming to use a treeview to list data informations, and a form to edit each single entry.
My main question is still: could a bindingsource be bound to a couple of joined tables?
|
|
|
|
|
My main response is still: it depends on the control.
|
|
|
|
|
Hi Guys,
does anyone know of a way / programme to convert Powershell scripts into C# code?
i have a short script that i need to convert and it is proving pretty tricky!
Many Thanks,
Phil
|
|
|
|
|
Hi,
Maybe seeing the original Powershell script could help
|
|
|
|
|