|
For the past few months Ive had to design a way of keeping a log\ tracking changes to a web app.
Now as this was a urgent requirment, I just kinda got on and did it in the way I knew how to.
But im now at the point where im logging more data and obviously want to be more efficient in how i do this.
So this is what I currently do.
Example:
1.User wants to change a contact phone no, brings up the record, it reads "1234567" user enters "123456789"
presses update and the code will do the following
2.I will do a db look for that customer record (i passed a paramter of the customerid),
grab the contact no and store it in a string, close the connection.
// I question this bit as I all ready pulled out the value once to show to the user (1.)
3.Im now going to update my record with the new value, done.
4. Now i need to log the old value and the new value into my log class which is like
public class Log
{
private bool xLogRecordInserted;
ProfileCommon profile = HttpContext.Current.Profile as ProfileCommon;
ProfileBase pb;
public Log(string NewComments, string OldComments, int LogCategoryOID, int OID)
{
try
{
string strInsertLog = "INSERT INTO tbl_Log (UserOID, dtRasiedDate, Comments, Comments2, LogCategoryOID, RelatedRecordOID) VALUES (@UserOID_2, @dtRasiedDate_2, @Comments_2, @Comments2_2, @LogCategoryOID_2, @RelatedRecordOID_2)";
Connection c = new Connection("Connection_Log");
//--Connection
SqlConnection con = c.Connect();
//--Commands
SqlCommand cmd_InsertLog = new SqlCommand();
cmd_InsertLog.Parameters.AddWithValue("@UserOID_2",profile.UserID);
cmd_InsertLog.Parameters.AddWithValue("@dtRasiedDate_2", DateTime.Now);
cmd_InsertLog.Parameters.AddWithValue("@Comments_2", NewComments);
cmd_InsertLog.Parameters.AddWithValue("@Comments2_2", OldComments);
cmd_InsertLog.Parameters.AddWithValue("@LogCategoryOID_2", LogCategoryOID);
cmd_InsertLog.Parameters.AddWithValue("@RelatedRecordOID_2", OID);
//--Open Connection
cmd_InsertLog.Connection = con;
//--Command Types
cmd_InsertLog.CommandText = strInsertLog;
// Execute Query and count rows
int intAffectedRows = cmd_InsertLog.ExecuteNonQuery();
if (intAffectedRows > 0)
{
xLogRecordInserted = true;
}
else
{
xLogRecordInserted = false;
}
con.Close();
con.Dispose();
c.Disconnect();
}
catch (Exception ea)
{
xLogRecordInserted = false;
ErrorLog ErrorLogEntry = new ErrorLog("Log.CS", "Log", profile.UserName, ea.ToString(), "Class");
}
}
public bool LogRecordInserted
{
get {return xLogRecordInserted;}
}
}
|
|
|
|
|
Do you have a question to go with all those words?
Can you not pass old number as parameter to avoid excess database query?
Other than that your just logging a change with one query, how else would you be able to do it that would be better
|
|
|
|
|
What sort of database are you using here? I'd recommend putting some of that function into stored procs if you can.
If you update a phone number and log the previous one, you really want that operation to be atomic, which means it should run in a transaction. You could do this in code, but I'd argue a stored proc which replaces the phone number and logs the old one is they way to go.
Personally, I don't care for raw sql commands in code at all. It's ugly, fussy, not as secure, don't get exec plans and you increase the scope of transactions which could slow the system down.
Regards,
Rob Philpott.
|
|
|
|
|
So what is your question? Are you asking for some alternative methods to do this? I'd create a trigger on that table which fires when update happens. In that trigger, you can put the old value to the tbl_log . This will help you to avoid step2.
|
|
|
|
|
So my question was how can i make the code more effcient?,
my DBA wont allow triggers on the SQL db.
|
|
|
|
|
I have 2 tables
>>Tb_orders (date, ... , id_cust1, id_cust2)
>>Tb_customers(id_cust, name ...)
and I need to edit the fields id_cust1, id_cust2 using ComboBox
cBox1.DataSource = Tb_customers;
cBox1.DisplayMember = "name";
cBox1.ValueMember = "id_cust";
cBox1.DataBindings.Add("SelectedValue", Tb_orders, "id_cust1");
cBox2.DataSource = Tb_customers;
cBox2.DisplayMember = "name";
cBox2.ValueMember = "id_cust";
cBox2.DataBindings.Add("SelectedValue", Tb_orders, "id_cust2");
everything is clear but cBox1 and cBox2 have the same value. I dont know what I have to do..
modified on Saturday, January 31, 2009 2:03 AM
|
|
|
|
|
Try to use diffrent data source. I mean create separate Data source object.
|
|
|
|
|
Thank you!
|
|
|
|
|
Hi!
I'd like to send a message, which has an .mht body.
Can someone provide me with some info on how to do this?
I've seen the Chilkat.dll version from google, but for me it is not good
because of its license.
Thanks in adwance.
|
|
|
|
|
Found this link[^] from the discussion going here[^]
It uses the method name CreateMHTMLBody [^], I have never tried that but it may help
Be careful, there is no Undo Button(Ctrl+Z) in life.
|
|
|
|
|
Thanks,
Unfortunately it is a vb code, but I'll check if i find the same in c#
this cdosys looks interesting.
|
|
|
|
|
I am developing an application for Win mobile 6.0 in visual studio 2008 under smart device.This application involves reading and writing the data from a table in SQL server 2005 to a C# smart device form.I cannot read and write the data to the table made in SQL server 2005 to c# form. Plz someone help me with the steps to be followed to achieve this. Also help me with the steps for database connectivity.
Thanks.
|
|
|
|
|
I take it the System.Data.SQLClient .Net namespace is not available to you?
|
|
|
|
|
Could you tell me one thing where this SQL Server 2005 will be located? Correct me If I am wrong but can you use( or deploy) SQL Server 2005 on Win Mobile? I don't think so. Yeah but you can use SQL Server Compact Edition for Windows Mobile.
Be careful, there is no Undo Button(Ctrl+Z) in life.
|
|
|
|
|
Good Day Fellow Coders;
Given this string coming out of a database field (potentially 10's of thousands of records at a time).
I know that only the first sections will be unique.
I don't know how many of the other sections will be there.
strRef = "Section0.Section1.Section2.Section3.Section4.Section5.Section6.Section7.Section8.Section9"; etc...
I want to create a treeView and I want the nodes to have these properties
//what level is this node
level = level;
//create a tag id
idx = idx + 1;
//create a new tree node
Node = new TreeNode(Name);
//name it
Node.Name = Name;
//give it some text
Node.Text = Name;
//create the tag id
Node.Tag = level + idx;
//assign an image depending on level
Node.ImageIndex = 1;
//assign a selected image depending on level
Node.SelectedImageIndex = 1;
I have done this with spaghetti code about 822 lines but it's only about 97% reliable but all the properties get assigned.
I have also done this using recursion it is 100% reliable but I don't know how to assign the different properties during the recursion process.
I have been working on this a few weeks I have read a couple of books recommended by you folks and have learned a whole lot about how to make a folder browser but this is not quite the same. But I have not been able to solve this yet.
I'm stuck can anyone get me movin in a right direction again.
TIA
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
give some sample data and an example of how you want the tree veiw to be displayed. Im unsure to your requirements
|
|
|
|
|
Sample data might be something like this
strRef = "North Campus.Physics Building.North Side.Floor5.Room 222.East Side.Book Vault 3.1147.B0.shelf 4";
Tree should look like
North Campus
Physics Building
North Side
Floor5
Room 222
East Side
Book Vault 3
1147
B0
shelf 4
Build 1259
North Side
Floor1
Room 21
West Side
Closet n5
shelf 4
Is this what you requested?
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
ok i think i see what you want now. I will give some code guideline, sorry if its not what you need thou
foreach(DataRow row in DataTable)
{
string[] parts = row["ColumnName"].ToString().Split('.');
TreeNode baseNode = RootNode;
foreach(string s in parts)
{
TreeNode temp = CheckNodeExists(s, baseNode);
if(temp == null)
temp = baseNode.AddNode("ID", "Name", "Image")
baseNode = temp;
}
}
public TreeNode CheckNodeExists(string nodeText, TreeNodeCollection nodes)
{
if(nodes == null || nodes.Count == 0)
return null;
foreach(TreeNode node in nodes)
if(node.Text == nodeText)
return node;
return null;
}
Please let me know if this is not what you want and i will try to offer more help
|
|
|
|
|
maybe this would help...this is the recursion I am currently using.
fullRef is the name of the variable from the database
Now in here I'm not sure where I can add properties to the Nodes.
string[] strArr = fullRef.Split('.');
List<string> NODES = new List<string>(); //Save nodes
foreach (string str in strArr)
NODES.Add(str);
InsertNodes(treeView1.Nodes, NODES);
}
treeView1.CollapseAll();
treeView1.SelectedNode = treeView1.SelectedNode = treeView1.Nodes[0].Nodes[0].Nodes[0];
treeView1.EndUpdate();
this.Cursor = Cursors.Default;
}
}
TreeNode AddNode(TreeNodeCollection Parent, string text)
{
TreeNode temporaryNode;
foreach (TreeNode node in Parent)
{
if (node.Text == text)
{
return node;
}
}
return Parent.Add(text);
}
void InsertNodes(TreeNodeCollection treeviewNodes, List<string> _nodes)
{
if (_nodes.Count == 0)
return; //Recursive exit
TreeNode TempNode = AddNode(treeviewNodes, _nodes[0]);
_nodes.RemoveAt(0);
InsertNodes(TempNode.Nodes, _nodes); //Recursive calling
}
TIA
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
memory allocated on heap in method referenced by local variable declared within the method - will memory be reclaimed/collected automatically by CLR?
Thanks
dev
|
|
|
|
|
Yes, when all references are gone (at the next garbage collection cycle). In your case, when the local variable goes out of scope.
Regards,
Rob Philpott.
|
|
|
|
|
devvvy wrote: in method referenced by local variable declared within the method
Huh, like this?
void Test()
{
var V = Test;
}
?
I are troll
|
|
|
|
|
no... more like this
<br />
public class Something<br />
{<br />
...<br />
public void SomeMethod()<br />
{<br />
SomeObj o = new SomeObj();<br />
o.DoSomeWork();<br />
return;<br />
}<br />
...<br />
}<br />
dev
|
|
|
|
|
Yup
I are troll
|
|
|
|
|
devvvy wrote: If I don't have this line "o" would stil lbe garbage collected on method exit right?
Or even earlier, if possible.
|
|
|
|