|
That's perfect - thank you so much.
|
|
|
|
|
In the Name of God
Hi
I have 2 question
1)does Filebrowser control have ablitty to search and select multiple photo at the same time?
if it is so how?
2)I want to split a cell to multiple row in gridline in C#
if you know suitable software or source code i need your help
For example, a person whose name is Jhon and has several job i want to show him in a one row with all his job
name job
jhon programmer
actor
thanks
|
|
|
|
|
1. Which one of these controls[^] are you interested in?
2. You may need to write the code for that yourself.
|
|
|
|
|
Don't post this everywhere - it duplicates work and annoys people.
You have this posted in QA, leave it there!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Hi All!
I'm developing a C# Windows Forms application, connected with an SQL DB.
The main problem is that my app doesn't always throw a DBConcurrencyException.
Where it works:
TextBox, binded with drag&drop
3 ComboBoxes, binded in code to properties
CheckBox, binded with drag&drop
Where it doesn't work:
ListBox, binded in code to a BindList
TextBox, binded with drag&drop
PictureBox, binded with drag&drop
Symptom:
If I start 2 instances of my app, then changing the data in the "working" controllers causes a DBConcurrencyException while changing the data in the controllers in the "doesn't work" category doesn't. In that case the last update to DB wins.
If you need some code snippet, please write back and I'll post it.
Thanks for your help in advance!
|
|
|
|
|
Yeah, this makes no sense at all. You've provided a lot of stuff that's completely irrelevant to the problem at hand.
A DbConcurrency problem occurs usually because the WHERE clause in the SQL is not finding 1 record to update but either 0 or more than one.
So what's causing that? Well, that depends on your database setup, your C# code and your SQL statements. None of which you provided.
|
|
|
|
|
Here is my C# code which updates the database.
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
UpdateDatabase();
}
private void UpdateDatabase()
{
if (this.Validate())
{
this.receptTableBindingSource.EndEdit();
try
{
this.receptTableTableAdapter.Update(this.receptDataSet.ReceptTable);
MessageBox.Show("Update successful");
}
catch (DBConcurrencyException dbcx)
{
DialogResult response = MessageBox.Show(CreateMessage((ReceptDataSet.ReceptTableRow)
(dbcx.Row)), "Concurrency Exception", MessageBoxButtons.YesNoCancel);
ProcessDialogResult(response);
}
catch (Exception ex)
{
MessageBox.Show("An error was thrown while attempting to update the database: " + ex.ToString());
}
}
}
private string CreateMessage(ReceptDataSet.ReceptTableRow cr)
{
return
"Database(Cancel): " + GetRowData(GetCurrentRowInDB(cr), DataRowVersion.Default) + "\n" +
"Original(No): " + GetRowData(cr, DataRowVersion.Original) + "\n" +
"Proposed(Yes): " + GetRowData(cr, DataRowVersion.Current) + "\n" +
"Do you still want to update the database with the proposed value?";
}
private ReceptDataSet.ReceptTableDataTable tempReceptDataTable =
new ReceptDataSet.ReceptTableDataTable();
private ReceptDataSet.ReceptTableRow GetCurrentRowInDB(ReceptDataSet.ReceptTableRow RowWithError)
{
this.receptTableTableAdapter.Fill(tempReceptDataTable);
ReceptDataSet.ReceptTableRow currentRowInDb =
tempReceptDataTable.FindByID(RowWithError.ID);
return currentRowInDb;
}
private string GetRowData(ReceptDataSet.ReceptTableRow custRow, DataRowVersion RowVersion)
{
string rowData = "";
for (int i = 0; i < custRow.ItemArray.Length; i++)
{
rowData = rowData + custRow[i, RowVersion].ToString() + " ";
}
return rowData;
}
private void ProcessDialogResult(DialogResult response)
{
switch (response)
{
case DialogResult.Yes:
receptDataSet.Merge(tempReceptDataTable, true, MissingSchemaAction.Ignore);
UpdateDatabase();
break;
case DialogResult.Cancel:
receptDataSet.Merge(tempReceptDataTable);
MessageBox.Show("Update cancelled");
break;
case DialogResult.No:
receptDataSet.RejectChanges();
receptDataSet.Merge(tempReceptDataTable, true, MissingSchemaAction.Ignore);
UpdateDatabase();
break;
}
}
|
|
|
|
|
You can find here the automatically (by drag&drop) generated SQL code. The problem occurs with "Ingredients", "HowTo" and "Picture".
<UpdateCommand>
<DbCommand CommandType="Text" ModifiedByUser="false">
<CommandText>UPDATE [dbo].[ReceptTable] SET [Name] = @Name, [Ingredients] = @Ingredients, [HowTo] = @HowTo, [IsBakeNeeded] = @IsBakeNeeded, [Difficulty] = @Difficulty, [WorkTime] = @WorkTime, [Cost] = @Cost, [Picture] = @Picture WHERE (([ID] = @Original_ID) AND ([Name] = @Original_Name) AND ((@IsNull_IsBakeNeeded = 1 AND [IsBakeNeeded] IS NULL) OR ([IsBakeNeeded] = @Original_IsBakeNeeded)) AND ((@IsNull_Difficulty = 1 AND [Difficulty] IS NULL) OR ([Difficulty] = @Original_Difficulty)) AND ((@IsNull_WorkTime = 1 AND [WorkTime] IS NULL) OR ([WorkTime] = @Original_WorkTime)) AND ((@IsNull_Cost = 1 AND [Cost] IS NULL) OR ([Cost] = @Original_Cost)));
SELECT ID, Name, Ingredients, HowTo, IsBakeNeeded, Difficulty, WorkTime, Cost, Picture FROM ReceptTable WHERE (ID = @ID)</CommandText>
<Parameters>
<Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="@Name" Precision="0" ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="Name" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@Ingredients" Precision="0" ProviderType="NText" Scale="0" Size="0" SourceColumn="Ingredients" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@HowTo" Precision="0" ProviderType="NText" Scale="0" Size="0" SourceColumn="HowTo" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Boolean" Direction="Input" ParameterName="@IsBakeNeeded" Precision="0" ProviderType="Bit" Scale="0" Size="0" SourceColumn="IsBakeNeeded" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int16" Direction="Input" ParameterName="@Difficulty" Precision="0" ProviderType="SmallInt" Scale="0" Size="0" SourceColumn="Difficulty" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int16" Direction="Input" ParameterName="@WorkTime" Precision="0" ProviderType="SmallInt" Scale="0" Size="0" SourceColumn="WorkTime" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int16" Direction="Input" ParameterName="@Cost" Precision="0" ProviderType="SmallInt" Scale="0" Size="0" SourceColumn="Cost" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Binary" Direction="Input" ParameterName="@Picture" Precision="0" ProviderType="Image" Scale="0" Size="0" SourceColumn="Picture" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Original_ID" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="ID" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="@Original_Name" Precision="0" ProviderType="NVarChar" Scale="0" Size="0" SourceColumn="Name" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_IsBakeNeeded" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="IsBakeNeeded" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Boolean" Direction="Input" ParameterName="@Original_IsBakeNeeded" Precision="0" ProviderType="Bit" Scale="0" Size="0" SourceColumn="IsBakeNeeded" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_Difficulty" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Difficulty" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int16" Direction="Input" ParameterName="@Original_Difficulty" Precision="0" ProviderType="SmallInt" Scale="0" Size="0" SourceColumn="Difficulty" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_WorkTime" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="WorkTime" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int16" Direction="Input" ParameterName="@Original_WorkTime" Precision="0" ProviderType="SmallInt" Scale="0" Size="0" SourceColumn="WorkTime" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_Cost" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Cost" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int16" Direction="Input" ParameterName="@Original_Cost" Precision="0" ProviderType="SmallInt" Scale="0" Size="0" SourceColumn="Cost" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="false" AutogeneratedName="ID" ColumnName="ID" DataSourceName="Recept.dbo.ReceptTable" DataTypeServer="int" DbType="Int32" Direction="Input" ParameterName="@ID" Precision="0" ProviderType="Int" Scale="0" Size="4" SourceColumn="ID" SourceColumnNullMapping="false" SourceVersion="Current" />
</Parameters>
</DbCommand>
</UpdateCommand>
|
|
|
|
|
Oh goody. You're using the designer generated crap...
Well, here's your UPDATE statements WHERE clause:
WHERE
(
([ID] = @Original_ID)
AND
([Name] = @Original_Name)
AND
(
(@IsNull_IsBakeNeeded = 1 AND [IsBakeNeeded] IS NULL)
OR
([IsBakeNeeded] = @Original_IsBakeNeeded)
)
AND
(
(@IsNull_Difficulty = 1 AND [Difficulty] IS NULL)
OR
([Difficulty] = @Original_Difficulty)
)
AND
(
(@IsNull_WorkTime = 1 AND [WorkTime] IS NULL)
OR
([WorkTime] = @Original_WorkTime)
)
AND
(
(@IsNull_Cost = 1 AND [Cost] IS NULL)
OR
([Cost] = @Original_Cost)
)
)
Now, if that ENTIRE pile of expressions matches either 0 or more than 1 records, you'll get the DbConcurrency exception.
The problem with this pile of crap is that you don't need 99% of it. All it should be using is the ID column. Your WHERE clause should look like this:
WHERE [ID] = @Original_ID;
That's it, nothing more.
|
|
|
|
|
Hi Dave,
I've tried
WHERE [ID] = @Original_ID;
but now I don't get any DBConcurrency exception, even with the controllers that were working.
Then I tried to add the non-working field (eg. HowTo) to the WHERE clause:
WHERE
(
([ID] = @Original_ID)
AND
([Name] = @Original_Name)
...
([HowTo]= @Original_HowTo)
...
)
and I've added the parameter @Original_HowTo:
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@Original_HowTo" Precision="0" ProviderType="NText" Scale="0" Size="0" SourceColumn="HowTo" SourceColumnNullMapping="false" SourceVersion="Original" />
After running the app, I tried to save a record but I've got an SQL Exception 0x80131904 The data types ntext and ntext are incompatible in the equal to operator.
|
|
|
|
|
Argh
It's of course OK with
([HowTo] LIKE @Original_HowTo)
Thanks!
|
|
|
|
|
As some may know, I'm currently writing my Syslog implementation on C#/.Net.
Since I want to be able to rotate the log files in different manners, I got an interface IWriter[^]. Currently there is only one derived class, FileSizeRotatedWriter[^]. I'm now facing the problem that a class which rotates the Logfiles is non-existent and the FileSizeRotatedWriter does also the Rotation, which is not a really good design. I though about making a class RotationWriter deriving from an interface IRotator, which would make me able to assign any Rotator to the FileSizeRotatedWriter, but stumbled upon several problems:
- Writing to the Log directory is secured by a locking mechanism
- Both the Writer and the Rotator need to know the name of the currently used logfile
- The writer needs to keep the stream to the logfile open as long as possible, since each open/close operation costs time
I thought a bit about each of these problems, and found different solutions.
-- Have a third class which handles the resources
-- Notify the classes of changes by using events [bidirectional]
-- Let the FileSizeRotatedWriter instantiate a new Rotator any time something has changed, or push the changes down by an event [unidirectional]
I'm kinda stuck on this, and maybe need to go out and refresh my head. Any thoughts on this are greatly appreciated.
Edit: The full source code can be found at the Springlog Workspace[^]
The console is a black place
|
|
|
|
|
Marco Bertschi wrote: The writer needs to keep the stream to the logfile open as long as possible
I am of the opinion that that is a bad idea. Just as with a database I want a resource "open" as briefly as possible.
Otherwise, I got nothin'.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
I agree with PIEBALDconsult. In my experience with a similar facility we use for in-house debugging, the best approach is to open the log, append the data, and close it again periodically. The expense of the open/close is overwhelmed by the requirement to ensure as much data is secured as possible in the event of a catastrophic failure.
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote: The expense of the open/close is overwhelmed by the requirement to ensure as much data is secured as possible in the event of a catastrophic failure.
I agree on that, but if the stream has set AutoFlush to true this means that the data is written as soon as the Write operation is called, or am I wrong?
The console is a black place
|
|
|
|
|
In theory, yes. AutoFlush should "call" Flush immediately after every write. But... would I trust it for a critical log? Personally, no. I'd use File.AppendAllText or whatever to do the open-write-close anyway just to ensure that the log is closed between writes - so it can be backed up, copied, or examined without closing the application if nothing else.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Gotcha.
Now I still need to share the name of the logfiles between Writer and Rotator, and I'm tempted to do this with events. Or maybe a third FileWriteResources class? I'm brain-dead right now.
The console is a black place
|
|
|
|
|
I'd probably go with the third class which handles all actual file based stuff - unless performance is seriously going to be a problem in which case you want the minimum-time write solution and to heck with the rest being tidy!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
OriginalGriff wrote: in which case you want the minimum-time write solution and to heck with the rest being tidy!
And there is my problem: I want / need both... I also thought about making the Rotator a singleton | static class which is triggered by the Writer (in certain time frames, e.g. once a minute or something like that). This would make it tidy and reasonably fast, since only the write but not the rotation time is critical.
The console is a black place
|
|
|
|
|
Marco Bertschi wrote: the data is written as soon as the Write operation is called
I'd be concerned about modern drive technology caching the writes regardless.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
I made the experience that AutoFlush does what it says, but will consider that.
The console is a black place
|
|
|
|
|
XmlDocument doc = new XmlDocument();
string place = String.Format("http://maps.googleapis.com/maps/api/geocode/xml?latlng=13.020164575569374,77.92610049247741&sensor=false");
doc.Load(place);
XmlNode element = doc.SelectSingleNode("//GeocodeResponse/status");
Am getting the XML document from google maps services. but am getting 403 forbidden error. While i copy the link and run in a browser then am getting that XML document which i need. I do have an api key , client ID or signature. I tried eveything in that link. But none worked out. Help me in solving it. thanks in advance.
|
|
|
|
|
Strange. Can you receive it with
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(place);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
etc.?
|
|
|
|
|
Thanks for your reply. I got that error because my proxy was restricting my web request. Now i have bypassed the proxy and got a readable address from latitude and longitude.
|
|
|
|
|
I need to clear a listbox from a class other than the form where it exists. Any idea why this isn't working? I'm getting no error messages when I compile and I am seeing the Console.WriteLine text I also added in the same function. I can call this function from within my form and it behaves as expected. I tried setting the listbox to public despite the fact I wasn't getting protection level errors but that made no difference.
Just to clarify what I'm doing here... I have a form that includes a panel of user controls from another class. So when I selected and item from otherListBox I want to clear the mainListBox in a MyForm. Heres my code:
MyForm
public void ClearMainListBox()
{
Console.WriteLine("echo");
mainListBox.Items.Clear();
}
OtherClass
private void otherListBox_SelectedIndexChanged(object sender, EventArgs e)
{
MyForm mf = new MyForm();
mf.ClearMainListBox();
}
|
|
|
|