|
Something like this then?
try {
dtDate = DateTime.Parse(stringDate);
if (dtDate > startDate && dtDate < endDate) {
row["NEW_DATE_FIELD"] = stringDate;
myTable.ImportRow(row);
}
} catch (FormatException) {
row["NEW_DATE_FIELD"] = "Invalid Date";
myTable.ImportRow(row);
}
Alan.
|
|
|
|
|
Hi everyone
I have been programming in c# for some time now. Actually during a review of my code a question came up...
What is the most efficient way of creating public variables in an c# application that allows these variables to be globally accessible across the application?
I invite responses and views on the subject
Thanks in advance...
rome'
|
|
|
|
|
I would suggest as Properties in a class
|
|
|
|
|
thanks for your prompt reply...
to take this further...
would the properties be a part of a static class or a singleton object?
Thanks...
rome'
|
|
|
|
|
Ive read that its more (memory) efficient to use a singleton class, but the exact logic eludes me at the moment. Personally I tend to take the lazy option and make it static. However Id avoid the whole issue entirely given the choice!
[Edit: a quick google turned up this: http://my.opera.com/zomg/blog/2007/09/17/singleton-pattern-vs-static-classes[^] which doesnt quite prove my point, but might be interesting reading for you]
modified on Tuesday, August 12, 2008 11:45 AM
|
|
|
|
|
This information was indeed very useful...
Thanx
rome'
|
|
|
|
|
How about using settings - either application, or user if they change?
|
|
|
|
|
Well friend thanks for your reply
I am using application settings....its just that i wanted to put all the settings into separate variables and have them accessible from a class...
right now what the programmers in my team have happened to do is the following
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(true);
objMdiForm = new MdiForm();
Application.Run(objMdiForm);
the properties are defined in MdiForm and they are being accessed from the instance objMdiform
i found that messy and i wanted to put them in a class..
Anyway thanks a lot for your insight...
Take Care
rome'
|
|
|
|
|
singleton approach sound's good .
While maintaining the application Static is nightmare
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
Hi,
I have a problem with an oracle DB which is installed with an utf8-characterset. I build a form in VS2005 where the user type in a SQL-selectstatement and the form executes it and displays the result. Everything works fine with a singlebytecharcterset.
For example:
String sqltext = "Select artext from tbl_ar";
DataTable schTable;
OracleDataReader rdr = null;
OracleCommand cmd = new OracleCommand (sqltext, OracleConnection, OracleTransaction);
rdr = cmd.ExecuteReader(CommandBehavior.KeyInfo);
schTable = rdr.GetSchemaTable();
DataRow fldDescr = schTable.Rows[0];
int len = (int) fldDescr[2];
In the database with the utf8-characterset the variable len hat the value 0f 90 instead of 30. Is there a way to get the correct result ?
Thanks in advanced
Stofel
|
|
|
|
|
Hi,
Check that your character set is compatible at client side (HKEY_LOCAL_MACHINE\Software\Oracle....)
Mika
|
|
|
|
|
We have developed winform application in C#. Here when user logout we are storing logout time in database. Right now we have a code written in formclosing event for updating logout time. But if any error occurs while application is running / if we kill process from windows task manager then its not updating logout time. So please can any one suggest whats the best way to update logout time in Database. Because next time when user enters into application we are displaying message that "you are already logged in (System Name)system. Please logout!" . So if application is closed and logout time is not saved then user will get this message. So we want to update even if any exception in app / closed intentionally from task manager. Is there any event to handle this???
Please reply its very urgent.....
Rashmi.M.K
|
|
|
|
|
I don’t think that this (killing the application from Task Manager) can be handled with in the application itself.
And in fact, there can be n number of scenarios like this:
• What if I Shut Down my computer.
• What if there is hard disk crash.
|
|
|
|
|
Solution
1. Create a timer thread, that will send message if you dont get message application is dead .
2. Trace the Process of the application , if you dont find the process
the application is dead ( this has to be done from other process <new thread="" wont="" work="">, so u have 2 process )
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
thank u for good suggestion...
Rashmi.M.K
|
|
|
|
|
Dear All!!!
Please help me to resolve this error from the code i m posting here...my image is stored in ms-access database
as OLE object under the field name img_stream. I get "Invalid parameter used" error at "bmp = new Bitmap(ms)"
private void Page_Load(object sender, System.EventArgs e)
{
myAccessConnection = new OleDbConnection(connStr);
openAccessConnection();
OleDbCommand myCommand = new OleDbCommand("select img_stream from tblImg where img_id=4", myAccessConnection);
OleDbDataReader reader = myCommand.ExecuteReader();
if(reader.Read())
{
MemoryStream ms = new MemoryStream();
Response.ContentType = "image/jpeg";
byte[] imageContent = (byte[])(reader["img_stream"]);
ms.Write(imageContent, 0, imageContent.Length);
Bitmap bmp;
bmp = new Bitmap(ms);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
ms.Close();
closeAccessConnection();
}
else
{
closeAccessConnection();
}
}
String connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("App_Data/db1.mdb");
OleDbConnection myAccessConnection;
protected void openAccessConnection()
{
if (myAccessConnection.State == ConnectionState.Closed)
{
myAccessConnection.Open();
}
}
protected void closeAccessConnection()
{
if (myAccessConnection.State == ConnectionState.Open)
{
myAccessConnection.Close();
}
}
Please help me out..This error is annoying me since last week and no solution yet!!
Thankyou!!!
|
|
|
|
|
Try this
{
byte[] imageContent = (byte[])(reader["img_stream"]);
MemoryStream ms = new MemoryStream(imageContent );
Bitmap bmp;
bmp = new Bitmap(ms);
bmp.Save(ms, ImageFormat.Jpeg);
closeAccessConnection();
}
Rashmi.M.K
|
|
|
|
|
Dear Sender!!!My error is still there..I have tried your instruction but no way out!!Please help...
|
|
|
|
|
Try this.. its working fine here.. i have executed your code its working.
{
byte[] imageContent = (byte[])(reader["img_stream"]);
MemoryStream ms = new MemoryStream(imageContent );
Image bmp = new Bitmap(ms);
bmp.Save(ms, ImageFormat.Jpeg);
closeAccessConnection();
}
Rashmi.M.K
|
|
|
|
|
I have tried your instruction but now i m getting following errors:
1. 'Image' is an ambiguous reference
2. The type or namespace name 'bmp' could not be found (are you missing a using directive or an assembly reference?)
I m using following namespaces:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
and i've used no image control...Please help!!!
|
|
|
|
|
u are reading image from Database. After this where do you want to display? what exactly you want to do?
Rashmi.M.K
|
|
|
|
|
Yes i m reading image from database and i want to display that on web page.
|
|
|
|
|
hi guys! I have a problem with the sql exception what I am getting while I am trying to upload a PDF file in a database. I have set the field for the document to be varbinary(MAX) so I will not have any problems with the size, but the exception says that my file is over the limit and I am getting this message when I am trying to update the table, at the last line of the code. Here is the code:
SqlConnection conn = new SqlConnection(some connection);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * FROM Table", conn);
SqlCommandBuilder MyCB = new SqlCommandBuilder(da);
DataSet ds = new DataSet("Table");
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
FileStream fs = new FileStream(@"C:\\PDFdocument"+"\\" + PDF, FileMode.OpenOrCreate, FileAccess.Read);
byte[] myData = new byte[fs.Length];
fs.Read(myData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
da.Fill(ds, "Table");
DataRow myRow;
myRow = ds.Tables["Table"].NewRow();
myRow["Document"] = myData;
myRow["ID"] = fileID;
ds.Tables["Table"].Rows.Add(myRow);
da.Update(ds, "Table");
how I can solve this issue? Thx ahead
|
|
|
|
|
|
i am trying to take under control of changing datarows. when there is a change i want to ask user whether he/she wants to save changes or discard changes. to accomplish this i am using rowchanged event
private void Form1_Load(object sender, EventArgs e)
{
this.kisiTableAdapter.Fill(this.denekDataSet.Kisi);
denekDataSet.Kisi.KisiRowChanged += new denekDataSet.KisiRowChangeEventHandler(Kisi_KisiRowChanged);
}
void Kisi_KisiRowChanged(object sender, denekDataSet.KisiRowChangeEvent e)
{
DataRowAction drc = e.Action;
if (drc == DataRowAction.Change)
{
DialogResult dr = MessageBox.Show("do you want to save changes!", "warning", MessageBoxButtons.YesNo);
if (dr == DialogResult.No)
{
e.Row.RejectChanges();
}
}
}
when there is a change this event works. and if user choice is "no" it works perfectly. but dialog result is "yes", there is a problem appears. changes are not apply to the database(restart the program). everything same as before the change action.
i tried different ways but it causes different errors(exception).
void Kisi_KisiRowChanged(object sender, denekDataSet.KisiRowChangeEvent e)
{
DataRowAction drc = e.Action;
if (drc == DataRowAction.Change)
{
DialogResult dr = MessageBox.Show("do you want to save changes!", "warning", MessageBoxButtons.YesNo);
if (dr == DialogResult.No)
{
e.Row.RejectChanges();
}else
{
kisiTableAdapter.Update(denekDataSet.Kisi);
}
}
}
after changing it calls many times messagebox for asking choice then produces InvalidOperationException and stops.
how can i solve this problem, it makes me anger and tired.
please help me , or show me a different way.
my intention is tracking changes and asking right question.
thanks for interests
::CTBRS::
|
|
|
|