|
I'm exposing a recorded history of events (changes to a database), in the order that they occured. I expect to update the queue periodically. Original order of events is important.
I expect the user to periodically consume this information, in order, and then come back for more. So I was using a queue as it enables them to dequeue at will, while maintaining the original order, and keeping track of which events they have already noted/processed.
The user really only needs to dequeue (ie, remove one item at a time, and be able to tell that they have consumed all the items currently available).
|
|
|
|
|
If the user tries to dequeue as you are trying to enqueue, I think odd things can happen. It may be better to instead expose an event for when a new event should be posted, and have the user catch that event and add the item to a local queue, which it can dequeue when convenient.
|
|
|
|
|
Consider an event for that. Among other things it allows multiple listeners.
|
|
|
|
|
Heh. Actually, this code was written to prevent the user from having to deal with events. I'm wrapping a COM object which does raise events, but has complexities and issues that are problematic. This code maps an event raiser to something a user can poll.
If those are the primary concerns, I'll stick with this model for now. My stress tests should tell me how much collision I'm seeing during my internal enqueue.
Thanks everybody!
|
|
|
|
|
Then maybe have Enqueue and Dequeue methods.
|
|
|
|
|
How can we use XML file to configure Visual studio post build event?
|
|
|
|
|
This makes no sense. What exactly are you trying to accomplish??
Post Build events are stored in the project file. So where does this XML file come into play??
|
|
|
|
|
You can create a custom MSBuild file to build the project, and then your post build actions.
Then use MSBuild to build your project, instead of building from Visual Studio.
|
|
|
|
|
Server Error in '/bliss' Application.
Incorrect syntax near 'w'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'w'.
Source Error:
Line 83: SqlDataAdapter da3 = new SqlDataAdapter(dept_Abr, con);
Line 84: DataSet ds3 = new DataSet();
Line 85: da3.Fill(ds3);
Line 86: string fun_abr = ds3.Tables[0].Rows[0][0].ToString();
Line 87:
Source File: c:\bliss\www\www_ca_view.aspx.cs Line: 85
Stack Trace:
[SqlException (0x80131904): Incorrect syntax near 'w'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +925466
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800118
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1005
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +7
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +141
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +86
www_www_ca_view.refno() in c:\bliss\www\www_ca_view.aspx.cs:85
www_www_ca_view.Page_Load(Object sender, EventArgs e) in c:\bliss\www\www_ca_view.aspx.cs:64
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
|
|
|
|
|
Your SQL query is broken. That is pretty obvious and why I've given you a 1, because you've clearly not even tried to understand before wasting our time here. Furthermore, you haven't shown us the SQL query you're using so there is no way we can possibly tell you what's wrong with it, except you have a stray 'w' in it.
|
|
|
|
|
thank u.. am very much new to .NET so ..
|
|
|
|
|
So far I am not very impressed with the story line. The characters are two dimensional and the plot is obvious,.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
You might want to look at the stack trace next time to get a better clue of where the error actually is.
|
|
|
|
|
.
As Dave said, look at the details provided by the stack trace.
And don't use release builds when there are still big issues in your code; with a debug build, the stack trace would provide actual line numbers rather than offsets.
|
|
|
|
|
Hi,
I wrote a code to export my data in gridview to excel. But at runtime it throws an exception saying "syntax error in INSERT TO" on execution of the command. I stepped through the code to see the output of the sql statement and I see nothing wrong with it. Can anyone assist me quickly on this please? Very many thanks in advance.
NB: The table creates perfectly, but the INSERT statement gives the exception.
My Code:
public static void ExportStudentsToXls(string filepath, List<Student> students)
{
using (ExcelHelper helper = new ExcelHelper(filepath))
{
helper.Hdr = "YES";
helper.Imex = "0";
Dictionary<string, string> tableDefinition = new Dictionary<string, string>();
tableDefinition.Add("StudentID", "int");
tableDefinition.Add("RegNo", "varchar(50)");
tableDefinition.Add("Surname", "varchar(100)");
tableDefinition.Add("Firstname", "varchar(100)");
tableDefinition.Add("Middlename", "varchar(100)");
tableDefinition.Add("LevelID", "int");
tableDefinition.Add("Sex", "varchar(10)");
tableDefinition.Add("DOB", "decimal");
tableDefinition.Add("Religion", "varchar(50)");
tableDefinition.Add("Nationality", "varchar(100)");
tableDefinition.Add("StateOfOrigin", "varchar(100)");
tableDefinition.Add("ClassID", "int");
tableDefinition.Add("ParentID", "int");
tableDefinition.Add("Address", "varchar(150)");
tableDefinition.Add("HomePhone", "varchar(20)");
tableDefinition.Add("MobilePhone", "varchar(20)");
tableDefinition.Add("Email", "varchar(255)");
tableDefinition.Add("NextofKin", "varchar(100)");
tableDefinition.Add("KinAddress", "varchar(200)");
tableDefinition.Add("BloodGroup", "varchar(50)");
tableDefinition.Add("Genotype", "varchar(50)");
tableDefinition.Add("Disability", "varchar(50)");
tableDefinition.Add("SessionID", "int");
tableDefinition.Add("TermAdmitted", "varchar(50)");
tableDefinition.Add("LevelAdmitted", "varchar(50)");
tableDefinition.Add("ClassAdmitted", "varchar(50)");
tableDefinition.Add("DateAdmitted", "decimal");
tableDefinition.Add("Hobbies", "varchar(50)");
tableDefinition.Add("Picture", "varchar(50)");
tableDefinition.Add("DateRegistered", "decimal");
tableDefinition.Add("Status", "varchar(50)");
tableDefinition.Add("Deleted", "varchar(5)");
helper.WriteTable("Students", tableDefinition);
string decimalQuoter = (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator.Equals(",") ? "\"" : String.Empty);
foreach (var student in students)
{
StringBuilder sb = new StringBuilder();
sb.Append("INSERT INTO [Students] (StudentID, RegNo, Surname, Firstname, Middlename, LevelID, Sex, DOB, Religion, Nationality, StateOfOrigin, ClassID, ParentID, Address, HomePhone, MobilePhone, Email, NextofKin, KinAddress, BloodGroup, Genotype, Disability, SessionID, TermAdmitted, LevelAdmitted, ClassAdmitted, DateAdmitted, Hobbies, Picture, DateRegistered, Status, Deleted) VALUES(");
sb.Append(student.StudentID); sb.Append(",");
sb.Append('"'); sb.Append(student.RegNo); sb.Append("\",");
sb.Append('"'); sb.Append(student.Surname); sb.Append("\",");
sb.Append('"'); sb.Append(student.Firstname); sb.Append("\",");
sb.Append('"'); sb.Append(student.Middlename); sb.Append("\",");
sb.Append(student.LevelID); sb.Append(",");
sb.Append('"'); sb.Append(student.Sex); sb.Append("\",");
sb.Append(decimalQuoter); sb.Append(student.DOB.Value.ToOADate()); sb.Append(decimalQuoter); sb.Append(",");
sb.Append('"'); sb.Append(student.Religion); sb.Append("\",");
sb.Append('"'); sb.Append(student.Nationality); sb.Append("\",");
sb.Append('"'); sb.Append(student.StateOfOrigin); sb.Append("\",");
sb.Append(student.ClassID); sb.Append(",");
sb.Append(student.ParentID); sb.Append(",");
sb.Append('"'); sb.Append(student.Address); sb.Append("\",");
sb.Append('"'); sb.Append(student.HomePhone); sb.Append("\",");
sb.Append('"'); sb.Append(student.MobilePhone); sb.Append("\",");
sb.Append('"'); sb.Append(student.Email); sb.Append("\",");
sb.Append('"'); sb.Append(student.NextofKin); sb.Append("\",");
sb.Append('"'); sb.Append(student.KinAddress); sb.Append("\",");
sb.Append('"'); sb.Append(student.BloodGroup); sb.Append("\",");
sb.Append('"'); sb.Append(student.Genotype); sb.Append("\",");
sb.Append('"'); sb.Append(student.Disability); sb.Append("\",");
sb.Append(student.SessionID); sb.Append(",");
sb.Append('"'); sb.Append(student.TermAdmitted); sb.Append("\",");
sb.Append('"'); sb.Append(student.LevelAdmitted); sb.Append("\",");
sb.Append('"'); sb.Append(student.ClassAdmitted); sb.Append("\",");
sb.Append(decimalQuoter); sb.Append(student.DateAdmitted.Value.ToOADate()); sb.Append(decimalQuoter); sb.Append(",");
sb.Append('"'); sb.Append(student.Hobbies); sb.Append("\",");
sb.Append('"'); sb.Append(student.Picture); sb.Append("\",");
sb.Append(decimalQuoter); sb.Append(student.DateAdmitted.Value.ToOADate()); sb.Append(decimalQuoter); sb.Append(",");
sb.Append('"'); sb.Append(student.Status); sb.Append("\",");
sb.Append('"'); sb.Append(student.Deleted); sb.Append("\",");
sb.Append(")");
helper.ExecuteCommand(sb.ToString());
}
}
|
|
|
|
|
kaycey90 wrote: sb.Append('"'); sb.Append(student.Deleted); sb.Append("\",");
sb.Append(")");
You have a , just before your closing ) . You don't need to put that in. BTW, why did you not consider using sb.AppendFormat instead? You could have saved yourself a lot of sb.Append work there.
|
|
|
|
|
Use a parameterised query! And if that's too hard (it's not), at least escape the input strings. You're going to break things when you meet Mr. O'Brien. (Not to mention Bobby Tables.)
SQL doesn't use double quotes, it uses single quotes. But I will re-emphasise, building a query string like this is the wrong way.
|
|
|
|
|
That deserves more than a 5.
|
|
|
|
|
I've heard of Bobby Tables, but could you provide a link to Mr. O'Brien?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
That's not a comic reference, just the first Irish name that came to mind. Irish surnames are the source of most real world accidental query failures of this kind.
|
|
|
|
|
Oh I see. The apostrophe.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
My post was just above and the first Irish name that came to mind was O'Brien?
|
|
|
|
|
Haha sorry Pete, I don't usually read the column of poster names when I'm perusing a thread!
|
|
|
|
|
I want to further emphasize what the others said. Use a parameterized query every time. It's safer and it's quicker if you reuse the command many times:
Set the command and add the parameters
Loop
Set the paramater values
Execute the command
Endloop
And what's with the Dictionary? There's no guarantee which order the columns will be in when you create the table. A List of Tuples might be a better idea.
|
|
|
|
|
In a Windows Forms application, I have a class Students and then I create a new object student inside the class Form1 which represents the main window of my application.
So far so good, but I need a second window which will show the user some of the student's data. Therefore I create a second class derived from Form, let's say
StudentsData : Form
and then I let a new object of that class be created inside the Form1 class, and again through ShowDialog() I let that new Window be visible.
What I do not succeed is to pass the student's data into that window. I think the real question should be, how do I make an object persist through different other classes/objects?
Any help would be appreciated.
|
|
|
|
|