|
DateTimes aren't stored as "text" in memory. They are stored as the number. See here: http://msdn2.microsoft.com/en-us/library/system.datetime.aspx[^]
I know you just want a quick and easy answer, but I'm trying to help you understand that you already have the data you need, you just need to format it when you display it in the control. 5/21/1984 and 21-MAY-1984 are the same date, and represented by the same "number" in memory.
But, if you really need to store the formatted version of that number in the datatable do something like:
ds.Tables[0].Columns.Add("FormattedCheck", typeof(string));
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["Check"].ToString() != "")
{
DateTime dt = DateTime.Parse(ds.Tables[0].Rows[i]["Check"].ToString());
ds.Tables[0].Rows[i]["FormattedCheck"] = dt.ToString("dd-MMM-yyyy");
}
}
Then bind the column to "FormattedCheck" instead of "Check" in your DataGrid.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Thanks Steve, it helps me a lot and working fine.
But the thing is here all the fields fetching from database are dynamic (in the sense, user have provision to select the fields in order, so that if user specify the "check" field in a specified place (say, 4th column), then the "FormattedCheck" is to be placed in the same 4th column. could u
help me plz?
thanks in advance.
john
|
|
|
|
|
Ah, I see you updated your code. The column "Check" is probably of type DateTime, so when you set your formatted string value, it gets parsed back into a DateTime.
You can either add a new column to table[0] of type text and set the formatted date time to it (I don't recommend doing it this way), or look into a way of making the control format the existing datetime column (recommended).
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Please try to use an ISO 8601 compliant format YYYY-MM-DD.
|
|
|
|
|
Hi all,
I am developing a calendar application in C# that will require to store certain data (like date events, calendar style and some other preferences)in a database.
My preference will be MS SQL 2005 (though could be MySQL, or similar), however I wish to know if I was to use MS SQL 2005, could I include some dlls or other resource in the install of the application, purely for the application to run, without having to install another copy of MS SQL 2005 in the client PC? Like a cut down version of MS SQL 2005 as client site install? Otherwise I may have to go for MySQL or MS Access 2003, to avoid extra cost of the application.
Any ideas an suggestions are welcome.
Thanks in advance.
Alain
|
|
|
|
|
You can go with Express, which needs to be installed, or Compact, which is basically a few dlls.
|
|
|
|
|
|
|
hey there
this is a brige ill hav to cross in a few months... will sql server compact or express work for a db with over 80 tables that will grow like crazy? and can it be made to install with my application?
Thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
well, sql server ce and sql server express will definitely work with more than 80 tables.
using ce or express depends on what you mean with "grow like crazy".
even sql server express is limited to 4gb db size (http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx).
if you have hundreds of thousand data rows, you'll probably consider using sql server express instead of ce.
i don't know how complicated it will be to deploy sql server express with your application automatically,
but with sql server ce it can be quite easily done with clickonce deployment
|
|
|
|
|
well im in the time and atendance industry.
some of our clients have over 3000 employees that would clock maby 4 - 6 times a day (each clocking becomes a record) so that could potentially mean 18000 records added to the db per day!
and thats just one of the tables... what do you recomend?
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
well, in this case i don't think you will use sql server ce for this scenario.
if you want to stick with microsoft products and don't want to spend money on license costs,
you should pick sql server express.
but keep in mind that db size is limited to 4gigs.
|
|
|
|
|
Joachim Kerschbaumer wrote: don't want to spend money on license costs
theres no licence fee????
(your link in the other post doesn work by the way, it says page not found)
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
|
I've been playing with Reflector recently (just out of interest of course ).
It seems to disassemble my VS projects fine. But when I try it on commercial assemblies (such as ITunes or something similar) I get an error saying that it could not find a command line interface.
Could anyone explain why this is so? Is it do with the language it was written in?
Mark.
|
|
|
|
|
MarkBrock wrote: But when I try it on commercial assemblies (such as ITunes or something similar) I get an error saying that it could not find a command line interface.
I suspect ITunes is not a .NET application.
MarkBrock wrote: Could anyone explain why this is so? Is it do with the language it was written in?
It is to do with what it is compiled to rather than what it is written in. If it is compiled to CIL (sometimes known as MSIL) Reflector will work - because that's what it is reflecting on. If it is a native DLL then it won't.
|
|
|
|
|
Thanks Colin .
Mark.
|
|
|
|
|
Hi,
I am getting to where I need to be, but slow going, and thanks for all of the previous help.
What I have so far...
Form loads and checks to see if xml file exists, if it does, it loads into runtime dataset and binds to datagrid:
CODE
private void Form1_Load(object sender, EventArgs e)
{
try
{
//File.OpenRead("C:\\DriveData.xml");
DataSet ds1 = new DataSet();
ds1.ReadXml("C:\\DriveData.xml");
dataGridView1.DataSource = ds1;
dataGridView1.DataMember = "DriveInfo";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
Console.WriteLine("Use the Open File button.");
}
}
On the form, if the datagrid is not populated, the user can load an excel file:
CODE
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Excel (*.xls)|*.xls";
openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
using (System.Data.OleDb.OleDbConnection objCon = new System.Data.OleDb.OleDbConnection(string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";",
openFileDialog1.FileName)))
using (System.Data.OleDb.OleDbCommand cm = new System.Data.OleDb.OleDbCommand("Select * From [sheet1$]", objCon))
using (System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(cm))
{
DataSet ds1 = new DataSet();
objCon.Open();
da.Fill(ds1,"DriveInfo");
objCon.Close();
ds1.WriteXml("C:\\DriveData.xml",XmlWriteMode.WriteSchema);
ds1.ReadXml("C:\\DriveData.xml");
dataGridView1.DataSource = ds1;
dataGridView1.DataMember = "DriveInfo";
}
}
}
This works great, but the part that I thought would be easier is harder for me at least.
I have a strong typed dataset created in my vs project with one datatable.
This dataset is part of the same initial form that loads and is binded to textbox, and other type controls.
I also have the binding source and binding navigator components at the bottom of the design screen for this dataset.
Here is what I want to do...
I want to write the strong typed dataset to an xml file, just like the weak typed one before, and then reload the xml file back to the dataset, maybe this step is not neccessary until I have changed data.
Anyway, I want this dataset editable/updated as if it were connecected to a dataadapter that was connected to a database.
My Save Button is greyed out on the binding navigator.
When I save changes, I want to have them save to the xml file, so that even if the application closes, the changes will be there.
Thanks, sorry for long winded.
|
|
|
|
|
pingboy wrote: I want to write the strong typed dataset to an xml file, just like the weak typed one before, and then reload the xml file back to the dataset,
DataSet.WriteXml("MyFile.xml");
DataSet.ReadXml("MyFile.xml");
only two letters away from being an asset
|
|
|
|
|
Hi all,
I have a Share Point server when i installed a windows service that use "remoting" technology - using IpcChannel. From the local machine everything work fine: i opened a website from the ie browser and when the SharePoint's server executed the code from OnInit method everything works fine (SharePoint server gets the proxy from Windows Service and wrote some results in a text file). The problem appears when i tried to access a website from another machine (other than the machine where i installed the windows service): so in OnInit method i initialized the remoting (create the IpcChannel, register the channel and i got the proxy object but when i tried to call a method from proxy object i received the following error message: Failed to create an IPC Port: Access is denied. I think that the problem is about the user security but i can't find the problem
Thanks a lot
Regards
Mitrea Bogdan
|
|
|
|
|
I am really turning nuts!
I have the following problem: I have a library that is MTA by design - and I cannot modify it, I have only the assambly. So far so good, but my application is a WPF application. And that in turn is STA by design.
So my simple question: How can both talk to each other? More precisely, there are no problems unless callbacks from the MTA-library are executed. I would like to give some feedback through the GUI, but nothing happens (ok, at least there is a caught exception that the GUI an only be modified from a STA thread... fine, so my delegate is still executed out of some library's thread)
The simple delegate does not work, implementing a wrapper with some event does not either. Posting a "real" Windows Message and grabbing data out of the wrapper would work, but that cannot be the best answer for my problem... can it??
Any help appreciated to make my code some kind of more professional.
Don Rolando
|
|
|
|
|
When you get a callback from the MTA library, just post to the Dispatcher of your WPF app to do the UI-related work. See MSDN's WPF Threading Model[^] for more info.
|
|
|
|
|
You are my man! Thanks a lot, that was it! The Dispatcher... argh, of course.
|
|
|
|
|
|
Thank a lot, but Judah's post gave me already the answer I searched for. (And it was about the same as the German page was about)
|
|
|
|