|
Problem resolved,
here is the code for the SQL connection:
<br />
Dim mycon As New SqlConnection(conString)<br />
<br />
Dim SQLConn As New SqlConnection() 'The SQL Connection<br />
Dim SQLCmd As New SqlCommand() 'The SQL Command<br />
<br />
SQLConn.ConnectionString = myconnection 'Set the Connection String<br />
SQLConn.Open() 'Open the connection<br />
<br />
SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command<br />
SQLCmd.CommandText = SQLStr 'Sets the SQL String<br />
SQLCmd.CommandTimeout = 60<br />
<br />
<br />
SQLCmd.ExecuteNonQuery() 'Executes SQL Commands Non-Querys only<br />
<br />
SQLConn.Close() 'Close the connection <br />
mycon.Close()<br />
Console.WriteLine("Connection Closed")<br />
The Bolded lin ei the new one which resolves my issue..
Thanks
|
|
|
|
|
Good
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
A couple of possibilities worth checking.
In Object Explorer right click on the SQL Server 2005 instance select Properties.
On the Connections tab check the value of Remote_query timeout.
On the Advanced tab check the value of Remote Login Timeout.
Either of these would take precedence over your connection string settings.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
Hi,
I have a simple console application using an if statement
if the user types "y" i would like form1 vb.net to be shown.
I tried my.forms.form1.show however this didn't work.
I added a console app to the main application by going on file / add / new project - to get the console application
as when i tried to add an existing item it didn't have a console application?
the console app works perfectly i just need to get on to the forms made in vb.net!
Many thanks
|
|
|
|
|
I don't think this is the way it should work. A console application is a simple text in text out app, that does not have any interaction with windows (aka forms). Simlarly a forms application does not (in general) interact with the console. If you are trying to offer an optional form according to user selection then your forms application should start with a form as dialog and then show form 1 or whatever else as appropriate.
|
|
|
|
|
You really can't do this. The .NET CLR doesn't support mixed-mode applications like this. This is because the startup environment for Console and Windows Forms app are very different and not compatible with each other.
|
|
|
|
|
First, let me say that as Richard wrote above, this is NOT the best way to do things. That said, if you actually do have a good reason for this, it can be done.
The trick is that a console app doesn't set up a message loop, which is what GUI apps need to function... It's easy, but you have to do it yourself.
[STAThread()]
static void Main(string[] args)
{
Console.WriteLine("Hit a key: ");
Console.ReadKey();
System.Windows.Forms.Form frm = new System.Windows.Forms.Form() { Text = "Test" };
System.Windows.Forms.Application.Run(frm);
}
Note that the form pops up behind the console, and that the console will remain open (Closing the console will end the program).
The same code works in WPF, except you create a new System.Windows.Application and call the run method on that instance.
(Tested in VS2008, CLR 3.5)
|
|
|
|
|
It can be done, but probably not a recommended practice.
See the following example;
1) Create a new console application project
2) Add a reference to System.Windows.Forms
3) Add a new Windows Form to the project
Copy the code below;
Module Module1
Sub Main()
Dim inputString As String = String.Empty
Do While inputString.Equals(String.Empty)
Console.Clear()
Console.Out.Write("Press the Y key to continue...")
inputString = Console.ReadLine
inputString = inputString.ToUpper
If inputString.StartsWith("Y") Then
Dim xForm As New Form1
xForm.ShowDialog()
End If
inputString = String.Empty
Loop
End Sub
End Module
This example will keep your console application in a loop, and everytime you press Y and enter the windows form will pop up.
modified on Wednesday, November 18, 2009 5:09 PM
|
|
|
|
|
I have a vb.net (WebForm) program that is for initial data entry and if the transaction needs to be corrected it doubles as Edit/Update. I have a series of DropDownLists that work perfect when in initial entry mode.
The problem comes when re-populating the transaction and appropiate dropdownlists are being populated in the code-behind.
The problem is that the dropdownlists need to be populated with all employees and then the specific employee that is to appear (normally selected, now force selected in code-behind) does not fire the SelectedIndexChanged Event a second time without a page level update.
Normally just changing the SelectedValue will cause the correct employee to appear. But, all of the elements of the dropdownlist have just been set, so the system does not recognize the new selection as one that is to be displayed.
With SelectedIndexChanged being a "Server Side" Event is there a way to force this event from the clientside in code-behind? Or maybe there is a way to reset the selectedindexchanged property to think is has not been changed yet?
If so, could you be kind enough to supply an example?
|
|
|
|
|
ASk this in the ASP.NET Forum.
|
|
|
|
|
Hi there..
I'm currently working on a project application in which I'm dealing with
multiple data reports. Use of multiple data reports are causing generation
of multiple temporary(*.tmp) files in the application directory.
So, I programmed a method to delete those temporary files from the app
directory.
The code for the method goes as follows:
Public Sub deleteTMPFiles()
Dim oFSO As New FileSystemObject
Dim oFolder As Folder, oSF As File
Set oFolder = oFSO.GetFolder(App.Path)
On Error GoTo KillErr
For Each oSF In oFolder.Files
If Right(oSF.Name, 4) = ".tmp" Then
SetAttr oSF.Path, vbNormal
Kill oSF.Path ' This line's generating error
End If
Next
Exit Sub
KillErr:
MsgBox Err.Description
End Sub
But the method is generating an error, when it comes to delete the file.
It gives a description as Permission Denied
I'm calling the method from MDIForm's unload event.
I just want to delete the temporary files from the application directory.
I've also tried the DeleteFile API function. It seemed as if the code ran
but reflected no changes in the system.
Any help will be appreciated..
|
|
|
|
|
Sounds like the file is in use still, and so will not be deletable.
By the way it looks like you are writing VB6 code. If you are posting in the future I suggest you include that information in your post, and probably also the header line.
It will get you some flac these days as VB6 is a legacy platform, no longer supported in any form by Microsoft. Though strangely I see MSDN subscribers can now download the VB6 IDE. Odd thing for microsoft to do.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
Hey there..
Thanx 4 ur reply..
But the file wasn't in use. I've already checked it many time..
Anyways, I've got my solution.
I used an alternative. I created an console application in C#
The code's as follows: (in C#)
using System;
using System.IO;
namespace DeleteTempFiles
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
FileInfo[] rgFiles = di.GetFiles("*.tmp");
foreach (FileInfo fi in rgFiles)
{
fi.Delete();
}
}
}
}
It simply deletes the *.tmp files from the application directory.
I'm just running this DeleteTempFiles.exe while unloading the form
using the following code in VB6
Shell(App.Path & "\DeleteTempFiles.exe")
Thanks again..
Nash - ThE CoDe sLiZeR
|
|
|
|
|
Have you ever wondered why your first approach doesn't work and your second approach does ?
|
|
|
|
|
Actually, My first approach was also working..
But after a day, it started showing me that error.
I've thought that it might be b'coz of the file being used somewhere.. in the memory. But the file wasn't in use..
Then I just got an idea of using that alternative.
No wonder, why it started showing that error.
I'd also googled about it before posting, many were having same problem as mine. But was with no answers left behind from anyone.
Well.. correction to my code before in VB6, I'd forgotten something there.
(in VB6)
Dim DeleteTempFiles<br />
DeleteTempFiles = Shell(App.Path & "\DeleteTempFiles.exe")
|
|
|
|
|
This is what probably happened:
1. When you tried to delete files from your own app, you got access denied because your own app was keeping those files open (your ReportViewer control).
2. When you moved the code to delete the files to another process (your console app) and call it when your are about to exit your app, your app is actually closed and releases all the handles it has on those files. So, your console app can happily delete those files.
|
|
|
|
|
Here is what is probably troubling you, BTW it uses some .NET terms but that isn't really relevant, the crux of the matter holds true in any language on a Windows system:
if you want write or delete access (anything other than read access) to a file that just got created (by yourself or someone else, does not matter), chances are you will find the file is being accessed by some other process, and your access is not granted.
The other process very likely is some server code that is there to assist you somehow. Candidates are:
- anti-virus software (Norton, McAfee, whatever)
- indexing software (Google Desktop, MS Office, whatever)
The common thing is these packages are looking all the time for new files, so they can inspect them.
Microsoft is aware of the consequences; Windows Explorer will try rename and delete attempts up to five times (with one-second interval), and only reports failure if the action continues to fail for that time.
The solution:
1. either use a different file name (not always acceptable)
2. or remove all background reader candidates (bad idea)
3. or implement the retry loop as Explorer has it (use a Windows.Forms.Timer for this)
BTW: if all you need is Read, make sure to allow others to read as well, i.e.
use File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)
Remark: in my experience, trying to open/append/close a file more often than once a second succeeds all the time, seems like the inspectors allow for at least one second of inactivity before opening the files themselves.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Thanx Luc..
I think this might be the problem.
I'll check my all codes once again. There's a high chance that I might have forgotten to close the recordsets or release resources while not working with them.
|
|
|
|
|
Hello all,
I am facing a problem while extact the Data from Excel in VB.Net
when I am having a Date Value and Double Value in Excel Spread Sheet.
When i am converting the Date Value Using Date.FromOADate(double args) Function, The Double Values in Excel are also converted to Date Format which is going Wrong. As Double Values in Excel Remain Double and Date Values must be converted to Date.FromOADate(...) as it is in OleDate Format which is again double.
I want to Convert Only the Date Field Values which are in Double format,
Not double values in Excel.
Please Suggest any Approach, It is Very Urgent.
Regards,
Uday.
|
|
|
|
|
Your question is not very clear at all.
Are you saying that you have two different date values (Ole and Double) in the same column of data and you want to be able to tell the difference between the two?
|
|
|
|
|
I will Explain You,
I have entered some double values in A3 Range of Excel.
Also some Date values in A3 Range of Excel.
While Retrieve this A3 Range Both the double value and Date values are showing as double.
So while converting the date value i used Date.FromOADate(double) it is OK for Date, But for the Range A3 there are also double values entered, This are also converting to Date value which must not happen for double values.
As Both Date value and Double Value in A3 Range are finally showing as double from excel,so i am not able to distingush for exact casting for Date values in A3 Range.
Please help me out.
Thanks & Regards,
Uday.
modified on Tuesday, November 17, 2009 12:15 PM
|
|
|
|
|
That explanation doesn't help much.
A3 is a single cell, or a Range consisting of one cell. Your explanation says that you have multiple values in A3 and that just isn't possible.
The only way to tell the difference between the two date values is to try to convert them to a date and see if the date comes back in a known range. If the date doesn't appear inside this range, try the other conversion. If it doesn't match either valid date range, you'll have to handle that value approriately.
|
|
|
|
|
janaswamy uday wrote: I want to Convert Only the Date Field Values which are in Double format,
Not double values in Excel.
If you are doing the converting then you need to apply the correct format depending on the source, whether it is a date or not.
|
|
|
|
|
dear All,
I understand but i will give a Article where the same problem is been raised.
Please see this Link There he has also same Problem :
Reading Excel Dates. Excel date gets converted to Double value in DotNet
------------------------------------------------------------------------
----> See this Link "http://social.msdn.microsoft.com/forums/en-US/vsto/thread/5b70f5e2-90c3-4824-99e4-8733be2e35ac"
I mean if we have Date Values and Double Values in a perticualr Range then how to find it is Date Value or Double Value ?
Regards,
Uday.
|
|
|
|
|
I already said, since the Date serial number is no different than a double, you have to either:
1) make sure that your dates do not end up intermingled with actual values or other date representations
2) try to convert the suspect date value into an actual date and test it for validity. If you know there cannot be any dates outside of a certain range, then you've got the wrong conversion if a date falls outside of that range. Try another conversion function and test again.
|
|
|
|