|
I am using the datareader to read through a foxpro table and when there are multiple records in the table it will only read the first one and then drop out of the loop. Any ideas on why it is doing this?
If DR.HasRows Then
While DR.Read()
random code here...
uploadDate = sql statement...
uplDate = New OleDb.OleDbCommand(uploadDate, objConnection)
DR = uplDate.ExecuteReader
DR.Read()
End While
End If
modified on Monday, April 12, 2010 3:10 PM
|
|
|
|
|
You're reusing the same reader to do something different which executes on the same connection. That's why it's dropping out of the loop. Change this to execute the second reader on a different connection if it's doing something with the data from the first query.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
It seems that you need to use two different Data Reader. DR is fine for the external while loop.
But inside the while loop you are re-updating its value which is leading to the problem..
Try using another instance of the datareader, and it would work completely fine.
|
|
|
|
|
Hi audience!
on several places ther is demanded in a very unconditional manner: "when starting a thread with aDelegate.BeginInvoke() always call the corresponding aDelegate.EndInvoke(IAsyncResult ar) .
For example see MSDN itself [ ^ ] .
But now i look in Reflector, how the Backgroundworker -class works, and i find:
public void RunWorkerAsync(object argument)
{
if (this.isRunning)
{
throw new InvalidOperationException(SR.GetString("BackgroundWorker_WorkerAlreadyRunning"));
}
this.isRunning = true;
this.cancellationPending = false;
this.asyncOperation = AsyncOperationManager.CreateOperation(null);
this.threadStart.BeginInvoke(argument, null, null);
}
And this.threadStart is simply a private class-variable of type WorkerThreadStartDelegate , which is defined as:
private delegate void WorkerThreadStartDelegate(object argument);
Since
this.threadStart.BeginInvoke(argument, null, null);
does not save the returned IAsyncResult , nor passes an AsyncCallback to the BeginInvoke() -call, i see no option for the backgroundworker, to call this.threadStart.EndInvoke(IAsyncResult ar) propperly.
So i think to myself: if the parallel processed method is void , actually there is no need to call aDelegate.EndInvoke(IAsyncResult ar) ?
I would be pleased of that, because that could simplyfy some of my codes.
So can anyone confirm my conclusion?
|
|
|
|
|
I think you've been reading MSDN far too closely and I should state at the outset that I don't have an answer to the question. The confusion around this issue must arise out of inconsistencies in the Microsoft documentation. For example, there is a disparity between your reference and the information in Event Based Asynchronous Pattern[^]. The first gives the impression that the world will end if the EndInvoke call is omitted, yet the second does just that and does not explain why we're still here.
I haven't found an example that demonstrates a problem caused by not calling EndInvoke or been able to come up with one of my own. My own best idea to make something go wrong was this:
internal void InvokeTest(Int32 count) {
IAsyncResult ar;
for (Int32 i = 0; i < count; i++) {
TaskDelegate t = Task;
ar = t.BeginInvoke(null, null);
ar.AsyncWaitHandle.WaitOne();
}
}
private void Task() {
throw new Exception('a', 64 * 1024);
}
I thought that the ignored exceptions on the invoked thread might be retained by the CLR until EndInvoke was called but find that there is no gradual upwards drift in memory useage (Process Explorer). If the Exception objects were not being collected it should be very obvious given the size of the associated exception message.
To err on the side of caution one should include EndInvoke but I can't find any compelling evidence one way or the other.
So no help from me then, but I thought your post was looking lonely!
Alan.
|
|
|
|
|
Thank you very much! Especially
Alan N wrote: ...but I thought your post was looking lonely! ...
shows a noble character, and i'm happy to see, such magnanimity still exists in the real world .
Finally i found an answer, and a reasonable reason to call Action<whatever>.EndInvoke() :
Exceptions of the sideThread are saved to the calling thread (May be you knew that already, to me it's new).
In Designmode there is no difference - the Debugger stops where the exception is thrown.
But in Release-mode it's important, and very dangerous, because a lost exception leaves the program running in an instable State!
using System.Windows.Forms;
using System;
using System.Threading;
namespace AsyncWorkerCs {
public partial class frmMain : Form {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.Run(new frmMain());
}
public frmMain() {
InitializeComponent();
btCreateError.Click += btCreateError_Click;
}
void btCreateError_Click(object sender, EventArgs e) {
var createError = new Action(CreateError);
createError.BeginInvoke(null, null);
}
void CreateError() {
Thread.Sleep(500);
throw new Exception("CreateError()!");
}
}
}
Hmm, now i've found a reason to call Action.EndInvoke, it's one more reason to deprecate the Backgroundworker-class, isn't it?
a very strong reason to deprecate it, since the dangerous behavior does not occur in Debug-mode.
So it causes its surprises really late.
regards
|
|
|
|
|
Here is my code, I trying to pass the full Name to floating div, when I click on the cell.
asp:DataGrid ID="gvResults" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BackColor="transparent" BorderColor="White" BorderStyle="None"
CellPadding="0" Font-Size="X-Small" PageSize="10" Visible="True" Width="500px"
CssClass="width-full cell-padding cell-top-align" ShowHeader="true" ShowFooter="false"
PagerStyle-Mode="NextPrev"
PagerStyle-Position="Top"
PagerStyle-HorizontalAlign="Left"
PagerStyle-CssClass="pageLinks"
PagerStyle-VerticalAlign="Bottom"
AlternatingItemStyle-BackColor="#F5F5F5" OnPageIndexChanged="PageIndexChanged_Click" OnSelectedIndexChanged="dgSchedule_SelectedIndexChanged" >
<Columns>
<asp:TemplateColumn HeaderText="" >
<HeaderTemplate>
<asp:LinkButton id="lblFullName" Width="130px" runat="Server" Text='↓ Full Name' />
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox BackColor="transparent" Font-Size="10px" BorderStyle="none" runat="server" ReadOnly="true" runat="server" onclick="showhide('CombinePat','none')" ID="txtFullName" ToolTip="Combine Patient" value= '<%# DataBinder.Eval(Container, "DataItem.Full_Name") %>' ></asp:TextBox>
<%--<asp:TextBox BackColor="transparent" ReadOnly="true" ID="txtFullName" BorderStyle="none" runat="server" Width="150px" Font-Size="10px" value= '<%# DataBinder.Eval(Container, "DataItem.Full_Name") %>' />--%>
</ItemTemplate>
<ItemStyle CssClass="grid-item" />
</asp:TemplateColumn>
THis is my floating div
<div id="CombinePat" class="modal display-none" >
<a href="javascript:;" class="close" onclick="showhide('none','CombinePat')">Close</a>
<h5>Combine Duplicate Patients</h5>
<ul class="form input label-xl margin-none border-none">
<li><label class="desc">Name</label><asp:TextBox ID="txtFullName2" runat="server"></asp:TextBox><%--<input type="text" size="45" />--%></li>
|
|
|
|
|
Hi, I'm trying to make a program (using .NET) in which its GUI is based around Microsoft's Windows Explorer. I want it so that I can edit "stuff" where the main file exploring bit is... I can do BandObjects which is the style of integration I think I'll need but I want it for the main body of explorer. For a better idea what I'm talking about, someone made a Registry Editor integrated into Windows Explorer and Mircosoft themselves do something similar with their Global Assembly Cache.
Could anyone give me an idea on how to go about such a thing?
Thank you.
|
|
|
|
|
You're going to need this[^]. THe sample you linked to uses this very library to heklp with this work.
Even though that library exists, it's not wise to write shell extensions (or in your case, a namespace extension) in .NET. If using .NET 1.x through .NET 3.5, you can only load a single version of the .NET Framework into a process (Explorer) at any one time. If the user has a different extension (or whatever else) using a different version of the .NET CLR than your extension is using, bad and unpredictable things will happen. Stuff like this is best left up to doing in C++, at least until .NET 4.0 comes out.
After that, you're on your own. What you're doing isn't normally done in .NET because of the massive amount of work required. Though, the library above does take care of a lot of that for you, the likelyhood of someone else here using it is extremely low. You're best source of information is going to be the people who wrote that library.
|
|
|
|
|
is there a way to overlay an image with a hue dynamically in .net like you can in adobe ps?
say you have a greyscale image (in my case, background of a progress bar)...
take the same image, overlay a hue (user/basic color selected), have progressbar with user color choice
would like to do this with a custom set of controls for customizing, any suggestions?
|
|
|
|
|
You can't do this with any speed in VB.NET. C# supports pointers and does a much better job. You could write the component to do the coloring in C# then use that in a VB.NET app.
There is a series of articles here by Christian Graus that deals with doing this very thing. All you have to do is search the articles for "Image Processing for Dummies" (seriously!)
|
|
|
|
|
I have written a GUI application using VC++2008 .NET to produce an entry summary declaration in XML format for my businses testers.
XML documents are handled using DOM and written using "doc->Save(filename)". When XML documents contain the standard opener <?xml version="1.0" encoding="utf-8" ?>, three non printable characters are written to line 1 column 1 of the document by the save action.
The client requires UTF-8, and so far the work around is to open each docuemnt in Altova and save it again.
Ger
|
|
|
|
|
Ger Hayden wrote: three non printable characters are written to line 1 column 1 of the document by the save action.
Not that I have noticed.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Somehow your file gets written with a Unicode byte-order mark.
You can get rid of it by creating a new UTF8Encoding(false) and using this when writing your xml.
The false refers to encoderShouldEmitUTF8Identifier parameter.
|
|
|
|
|
That did it - many thanks.
GER
Ger
|
|
|
|
|
Hi,
I was working a To-Do-List project. Notes adding to groups. Everything is fine, but, program not saves list in group view. Before restart program, list loading without groups. How to load with groups?
This is my code:
To Load List
On Error Resume Next
Dim FS = New System.IO.FileStream(AppDataFolder() & "\iNotes3\Me.int", IO.FileMode.Open)
lHeaders.Items.AddRange(BinFormatter.Deserialize(FS).ToArray(GetType(ListViewItem)))
FS.Close()
To Save List
On Error Resume Next
Dim FS As New System.IO.FileStream(AppDataFolder() & "\iNotes3\Me.int", IO.FileMode.Create)
BinFormatter.Serialize(FS, New ArrayList(lHeaders.Items))
FS.Close()
Add Note to List
Dim TodayDate As String
TodayDate = Date.Today
On Error Resume Next
If tHeader.Text = Nothing Then
tHeader.Select()
Else
Label1.Visible = False
lHeaders.Visible = True
Dim lvi As ListViewItem
lvi = lHeaders.Items.Add(tHeader.Text, 0)
lHeaders.Groups.Add(TodayDate.ToString, TodayDate)
lvi.Group = lHeaders.Groups(TodayDate.ToString)
lvi.UseItemStyleForSubItems = False
lvi.SubItems.Add(Date.Now, Color.Gray, Color.White, New System.Drawing.Font("Segoe UI", 8))
tHeader.Items.Add(tHeader.Text)
SaveHeaders()
End If
Thanks.
|
|
|
|
|
Hi,
I have used GDI+ Architect and I liked it for what it did.
I need to design a few A4 pages programmatically and need a WYSIWYG editor for it.
I downloaded GDI+ Architect from http://www.codeconfessions.com/[^] since mrgsoft.com is not working any more. But this version of the program seems to have some error when a saved file is opened again.
Does anyone have a working copy of it or suggest a free alternative for it?
Would appreciate any help
Som
|
|
|
|
|
If my C# code knows the name and path of a resource file in the solution explorer, I know how to read the resource file into a byte[] and then write it out somewhere else in the file system. In otherwords, export the resource file. But suppose all I know in code is the path to a folder in the solution explorer, for example Resources/InterestingFiles. How can I iterate through all the resource file names in that solution folder? If I could do that, I wouldn't need a hard-coded list of files embedded in my C# code, but could just iterate through a list of names and export all of them somewhere into the file system. I don't want a bunch of resource file names hard-coded in my C# code. I want a nice, tight loop where I can get one resource file name after another, something like the System.IO.Directory.GetFiles() static function within .NET that returns a string[] object containing all the file names within a directory.
modified on Saturday, April 3, 2010 6:08 AM
|
|
|
|
|
Hi,
When I tried to place files within a subfolder as you are suggesting they were not embedded into the assembly. Have you examined your assembly with a hex editor to see what you have in there?
Alan.
|
|
|
|
|
Alan N wrote: When I tried to place files within a subfolder as you are suggesting they were not embedded into the assembly.
I presume you set the resource file's Build Action to Embedded Resource, or at least Resource. If so, it will certainly be there.
Alan N wrote: Have you examined your assembly with a hex editor to see what you have in there?
Don't need to do that because I know they're there. I have a list of them embedded in the code and use the following code to successfully get at them and then export them to the file system:
Uri uri = new Uri("Resources/" + resourceFile, UriKind.Relative);
StreamResourceInfo sri = Application.GetResourceStream(uri);
Stream componentStream = sri.Stream;
I just don't want to have to remember to update that hard-coded list every time I add a new file to the Resources folder. It should be enough to put them into the folder through the solution explorer and set the Build Action to Resource. You shouldn't have to do anything more than that. My request in asking for help is, how can I pull out a list of relative paths so I can build the Uri for each embedded resource without hard coding the list in my C# code?
I've subsequently done a lot of sifting through MSDN on various classes such as Assembly, looking for something that would give me a collection of paths like Resources/InterestingFile but I haven't found anything that does the job.
|
|
|
|
|
Hi again,
Yes setting the build action to embedded resource does make a difference.
With the source file structure of
Resources (directory)
hidden (directory)
file1.txt
file2.txt
TfDll.dll
file3.txt
file4.txt
The following code
private void ShowResources2() {
Assembly a = Assembly.GetEntryAssembly();
foreach (String s in a.GetManifestResourceNames()) {
Console.WriteLine("NAME {0}", s);
if (s.Contains("TfDll.dll")) {
using (Stream rs = a.GetManifestResourceStream(s)) {
using (FileStream fs = File.Create("TfDll2.dll")) {
Byte[] buff = new Byte[8192];
Int32 read;
while ((read = rs.Read(buff, 0, buff.Length)) > 0) {
fs.Write(buff, 0, read);
}
}
}
}
}
}
outputs
NAME TfSync.MainForm.resources
NAME TfSync.Properties.Resources.resources
NAME TfSync.Resources.file3.txt
NAME TfSync.Resources.file4.txt
NAME TfSync.Resources.hidden.file1.txt
NAME TfSync.Resources.hidden.file2.txt
NAME TfSync.Resources.hidden.TfDll.dll
where TfSync and MainForm are the project's namespace and form. I also recreate an identical copy of TfDll.dll as TfDll2.dll.
Alan.
|
|
|
|
|
Thanks, Alan.
The reason my first attempt didn't work was because I had the Build Action of my resource files set to Resource and not Embedded Resource (an oversight on my part). When I made that change, The following code worked for me:
InstallationFiles = new List<string>();
Assembly a = Assembly.GetEntryAssembly();
foreach (String s in a.GetManifestResourceNames())
{
if (s.StartsWith("PHDInstallation.Resources."))
{
string fileName = s.Replace("PHDInstallation.Resources.", "");
InstallationFiles.Add(fileName);
}
}
|
|
|
|
|
|
Been there, done that. The array I got back had one entry in it: the path of my executable.
|
|
|
|
|
that does not fit the name of the method, nor my earlier experience with it.
I suggest you show actual code and give a detailed problem description.
|
|
|
|