|
Rather simple windows service that has a timer set to 1 minute from NOW and when that time is reached, writes an event log entry. That was the idea, but nothing happens.
Anybody know what i am doing wrong?
<br />
Public Class Service1<br />
Private alarmTime As Date<br />
Protected Overrides Sub OnStart(ByVal args() As String)<br />
' Add code here to start your service. This method should set things<br />
' in motion so your service can do its work.<br />
'Dim a As TimeSpan = Date.Now.Subtract(Date.Today.AddDays(1))<br />
'Dim tomorrow As Date = New Date<br />
'tomorrow = Date.Now.AddDays(1)<br />
<br />
'Me.alarmTime = New Date(tomorrow.Year, tomorrow.Month, tomorrow.Day, 0, 1, 1, 1)<br />
Me.alarmTime = Date.Now.AddMinutes(1)<br />
Me.Timer1.Start()<br />
End Sub<br />
<br />
Protected Overrides Sub OnStop()<br />
' Add code here to perform any tear-down necessary to stop your service.<br />
End Sub<br />
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)<br />
If alarmTime < Date.Now Then<br />
Me.Timer1.Stop()<br />
Dim MyLog As New EventLog() ' create a new event log<br />
' Check if the the Event Log Exists<br />
If Not Diagnostics.EventLog.SourceExists("SQLBackup") Then<br />
Diagnostics.EventLog.CreateEventSource("SQLBackup", "SQLBackup") ' Create Log<br />
End If<br />
MyLog.Source = "SQLBackup"<br />
' Write to the Log<br />
Diagnostics.EventLog.WriteEntry("SQLBackup", "Event fired at " & CStr(TimeOfDay), EventLogEntryType.Information)<br />
Else<br />
Dim remainingTime As TimeSpan = Me.alarmTime.Subtract(Date.Now)<br />
<br />
'Me.Label1.Text = String.Format("{0}:{1:d2}:{2:d2}", _<br />
'remainingTime.Hours, _<br />
'remainingTime.Minutes, _<br />
'remainingTime.Seconds)<br />
End If<br />
End Sub<br />
End Class<br />
|
|
|
|
|
hello
I have just started learning sql 2005 and i have create small table student with 3 columns studentID,firstname and lastname it's works fine i can insert,delete without any problem but when i delete any entry it dosent refresh the page i mean it delete record from sql database but it shows deleted entry in text boxes but if i close application and restart it then it dosent show deleted entry any help this is the code for delete
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click<br />
Dim SQL As String = Nothing<br />
SQL = "DELETE FROM Student WHERE StudentID = " & TextBox3.Text<br />
If MessageBox.Show("Are you sure you want to delete", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = MsgBoxResult.Yes Then<br />
conStudent = New Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Projects\SQL DataApplication\SQL DataApplication\Student.mdf;Integrated Security=True;User Instance=True")<br />
conStudent.Open()<br />
Try<br />
commStudent = New SqlClient.SqlCommand(SQL, conStudent)<br />
commStudent.ExecuteNonQuery()<br />
<br />
MsgBox("Item deleted", MsgBoxStyle.Information)<br />
Catch ex As Exception<br />
MsgBox(ex.Message)<br />
End Try<br />
conStudent.Close()<br />
conStudent.Dispose()<br />
Else<br />
Exit Sub<br />
End If<br />
End Sub
any help
waiting for your kind rep.
have a nice time
thanks
modified on Tuesday, April 29, 2008 4:00 PM
|
|
|
|
|
Just deleting the data form the database doe snot cause your display page to refresh. Depending on how you are displaying the data you need to handle that yourself after the delete is done.
Your query just removes the data form the DB. You have to either requery to display the data without that record now or at least refresh your page and clear out the data that is displayed.
|
|
|
|
|
Hello sir
first of all thanks for your rep.
sir i am new in sql and this is my first attempt to do some thing with sql server so can you please tell me more how get on with it i dont want code and copy past code does not solve the problem i want to understant it
and still i am trying
waiting for your kind rep.
have a nice day
thanks again
|
|
|
|
|
My suggesting is that once you do the query to delete the record you need to manually refresh the interface to show this.
It depends on bit on how you are filling your interface also. My guess is that if you are doing data binding then you may just be able to refresh the binding-manager to do this. If you are manually reading a record and placing data form the fields into the text properties of your UI then you have to at very least go back through the UI and clear out those text properties to show that the record has been deleted.
If you have a client side record-set that you have used to populate your UI from that is not really going to reflect the changes made int eh DB though until you have redone that read query so your record-set on the client may need to be flushed and refilled to show the change also.
There are so many different ways to do all of this, I can;t really cover them ALL here. I might suggest that you concentrate on searching how to do this keeping in mind the method you are using to read the data and display it in the first place.
|
|
|
|
|
hello sir
thanks for your rep.
i have tried few things but still i am no way near
this is what i have done
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click<br />
Dim SQL As String = Nothing<br />
SQL = "DELETE FROM Student WHERE StudentID = " & TextBox3.Text<br />
If MessageBox.Show("Are you sure you want to delete", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = MsgBoxResult.Yes Then<br />
conStudent = New Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\bablu\My Documents\Visual Studio 2005\Projects\SQL DataApplication\SQL DataApplication\Student.mdf;Integrated Security=True;User Instance=True")<br />
<br />
conStudent.Open()<br />
Try<br />
commStudent = New SqlClient.SqlCommand(SQL, conStudent)<br />
commStudent.ExecuteNonQuery()<br />
dsStudent.Clear() :confused:<br />
<br />
daStudent.Fill(dsStudent) :confused:<br />
<br />
MsgBox("Itemdeleted successfully", MsgBoxStyle.Information)<br />
Catch ex As Exception<br />
MsgBox(ex.Message)<br />
End Try<br />
conStudent.Close()<br />
Else<br />
Exit Sub<br />
End If<br />
End Sub
and i have also read tool tip when i select from IDE but now i dont know what to do
waiting for your kind help
have a good day sir
thanks
|
|
|
|
|
I think your problem here is that the dsStudent that you are using still has the data form when that record existed. You need to repopulate that data-set like you did originally once the database is changed. You are not removing data form the data-set, you are removing it by running a query against the database itself. Once you aer done with the delete clear your data-set and repopulate it from the database.
|
|
|
|
|
Hello sir
thank you very much for you help and finally job done
this is the final code and it's working fine
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click<br />
Dim SQL As String = Nothing<br />
conStudent = New Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\SQL DataApplication\SQL DataApplication\Student.mdf;Integrated Security=True;User Instance=True")<br />
SQL = "DELETE FROM Student WHERE StudentID = " & TextBox3.Text<br />
If MessageBox.Show("Are you sure you want to delete", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = MsgBoxResult.Yes Then<br />
conStudent.Open()<br />
Try<br />
commStudent = New SqlClient.SqlCommand(SQL, conStudent)<br />
commStudent.ExecuteNonQuery()<br />
MsgBox("Itemdeleted successfully", MsgBoxStyle.Information)<br />
Catch ex As Exception<br />
MsgBox(ex.Message)<br />
End Try<br />
conStudent.Close()<br />
Else<br />
Exit Sub<br />
End If<br />
dsStudent.Clear()<br />
Call LoadData()<br />
<br />
End Sub<br />
<br />
<br />
<br />
Private Sub LoadData()<br />
conStudent = New Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\SQL DataApplication\SQL DataApplication\Student.mdf;Integrated Security=True;User Instance=True")<br />
<br />
If conStudent.State = ConnectionState.Open Then<br />
conStudent.Close()<br />
End If<br />
<br />
Try<br />
conStudent.Open()<br />
daStudent.Fill(dsStudent, "Student")<br />
Label1.Text = Me.StudentBindingSource.Position<br />
Catch ex As Exception<br />
MsgBox(ex.Message)<br />
End Try<br />
conStudent.Close()<br />
conStudent.Dispose()<br />
<br />
End Sub
i am going to make few changes like connection here i am using connecting string more then one time so i can make sub for it and call it when ever it's needed
but the method i am using is this the one of the right method ? I just want to know your views as an expert and still
thanks again sir for your help
have a nice week end
take care
|
|
|
|
|
Without seeing the entire solution its hard to tell if this is the BEST way But I say that if it gets your job done then it is a step in the right direction.
My rules are make it work then make it pretty. You now have the 'works' part, now it is up to you to see if the way it works fits well with your overall design and if not, make it pretty I would assume that you are using the LoadData() sub already to load your data in the first place. If not then you might want to consider some refactoring in that area there.
Good luck, glad I could help a bit.
|
|
|
|
|
I'm trying to have my program display the PrintDialog and then print out some text. I assumed it would work similar to the open and save dialogs but when I try to double click on the printdialog it refuses to produce an event for when the person clicks the print button.
Can someone explain what is going wrong and how I can print a string of text. thanks
Mike
|
|
|
|
|
You need a printdialog and a printdocument. When printdialog's dialogresult=okay use printdocument.print to call the printdocument.printpage-event. There you have to use graphics.drawstring-method to print your string.
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
Thank you for your help. But I have a follow up question, when I double click on the printdocument I dragged and dropped into the program it creates a subroutine. However, when I run the program and click the print button of the printdialog it doesn't trigger the event. What is the event that the print button triggers?
thanks again,
Mike
|
|
|
|
|
printdialog1.document = printdocument1<br />
if printdialog1.showdialog = dialogresult.ok then printdocument1.printpage
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
Thank you again for your help. But I still don't know what event this code goes into because the printdocument1.printpage event isn't triggered and printdialogs don't appear to allow events.
thanks,
Mike
|
|
|
|
|
You put a button somewhere on your form that is usually labeled "print". Put the code in this button's click-event.
This is very basic stuff, you really should get a book, if you don't know how to do that.
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
Hi!
We are about to add help-functionality to our software. We are interesting in a Assistant like in Office Word. We want to interact between assistand and mainapplication. Like "Press here to open print-dialog" etc.
Anyone know about software we can use for this or anyone can give me an approach of how to code this?
Ofcourse I prefer a 3rd party solution.
Anyone can help?
|
|
|
|
|
Do you want it to be two separate applications, or all-in-one?
There are many ways to do this. You could (especially if you use two applications) write a value in a file and let the other program respond.
If you don't want to use two seperate applications you could use two forms, one with a "clippy" (the word assistant) background and transparency set.
Good luck!
|
|
|
|
|
It should be in the same application. But how to interact with the mainapplication from the assistant. As I said a link like "Press here to open printerdialog". And it should open the printdialog.
//henrik
|
|
|
|
|
i am using visual basic .net2005
please can you tell me how to get all of the file names i selected and pressed enter to play them with my application
i tried command$ and commandlineargs
but this give you just on file name
because every file sent to an instance of your application
i tried startupnextinstance
i got just on filename with every instance
but this is very slow way to get all file names
you have to wait all files to be sent
this mean 100 files=100 instance and long time
and above, this give aproblem with application
a messsege is shown(the application has aproblem and has to close)
i want away to get all of the files i selected and pressed enter to play with my application
thgether and in just one time
i think i have to use windows api
but i dont know how
and thank you...
|
|
|
|
|
|
Hi! I'm using a web service which is called through a stored proc from a windows service. Until few days back everything was working fine but suddenly I'm getting the following error.
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidCastException: Conversion from string "29/04/2008 13:45:57" to type 'Date' is not valid. at Microsoft.VisualBasic.CompilerServices.Conversions.ToDate(Stri
Further I'm able to run the webservice through code. My regional settings has dd/MM/yyyy settings for date i.e British. And I've also checked culture for my thread that is also british. I dont know what else is needed to get it working. Please guide me in getting a solution.
Thanks in advance.
Don't Quit
|
|
|
|
|
Try forcing the date/string format to dd/MMM/yyyy. This tends to remove any ambiguity in the conversion process.
You only need 1 machine/application in the system that does not look after the culture correctly to these problems. Text month usually solves this issue
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I am in the process of trying to find out what is the best practise for generating reports from an sql database useing different tables, that would be usefull to user on the Software access the DB, how do you do it? I come from a web design background and are now having to design a reporting engine for an ancient VB 6 application i have been lumped with....
I am used to having to build each report manually in html line for line and writting the formatting out in code, using sql querys for getting the data I need. but this is hard crap work and I would like to know if I am the only one doing it this way or do you have another way of doing it using some kind of report builder like crystal reports.
Its just there must be a better and faster way to get usefull reports from a db without the hard work building every line in the report from different querys and functions that jump all over the place in your application and db.
your insiteful comments will be greatly appreciated...
|
|
|
|
|
Try to avoid Crystal Reports/BO, you will see many unanswered queries here for that horrible thing. We use Reporting Services and are very happy with it, but there are a number of solutions out there. All will require a fair learning curve but at least most are stable (unlike CR).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi All,
I am using a Component One Flex Grid.
I have data populated in it, with one fixed row in the begining.
That grid basically shows the present godown stock of the plant (dgMatStockDn).
My Requirement:
When I right click on the first fixed column of the grid, it should give me a menu having menus "Insert", "Delete", "Copy", "Paste".
Suppose if my any of the previous stocks are same. I would like to copy the whole line again.
I will right click on the grid. Click "Insert". A new row will be inserted.
I will right click on that particular row. Select "Copy".
Then I will right click on the new row, select "Paste" and the same row should get copied here also.
Tell me the logic and also on which event of the datagrid should I right this.
I hope the requirement is clear.
Thanks and Regards,
|
|
|
|