|
Hi Vaani,
I do not have expertise on restoring SQL Server database programmatically. Howerver, you may try following code snippet to take backup of a SQL SERVER database from a remote machine. You will need to compile it and change the values to reflect your server.
BEGIN CODE
Imports System
Imports System.Data
Imports System.Collections
Imports Microsoft.SqlServer.Management.Common
Imports Microsoft.SqlServer.Management.Smo
Class Program
Private Shared Sub Main(ByVal args As String())
Dim bdi As New BackupDeviceItem("AdventureWorks.bak", DeviceType.File)
Dim bu As New Backup()
bu.Database = "AdventureWorks"
bu.Devices.Add(bdi)
bu.Initialize = True
AddHandler bu.PercentComplete, AddressOf Backup_PercentComplete
AddHandler bu.Complete, AddressOf Backup_Complete
' add percent complete and complete event handlers
Dim server As New Server("localhost")
bu.SqlBackup(server)
Console.WriteLine(Environment.NewLine + "Press any key to continue.")
Console.ReadKey()
End Sub
Protected Shared Sub Backup_PercentComplete(ByVal sender As Object, ByVal e As PercentCompleteEventArgs)
Console.WriteLine(e.Percent + "% processed.")
End Sub
Protected Shared Sub Backup_Complete(ByVal sender As Object, ByVal e As ServerMessageEventArgs)
Console.WriteLine(Environment.NewLine + e.ToString())
End Sub
End Class
END CODE
I hope this would be helpful .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
Hi all,
I'm currently doing a contract and vendor windows form application.
I have no problem creating reports, i.e listing contracts and vendors by their specialisation.
But now, I have one problem - I do not know how to do a report which list contracts due for renewal in 3 months. The thing is I have already did a search function in a form which would list the contracts due for renewal in 3 months, using the query builder(which reflects under ContractTableAdapter). However, my previous reports are created by drag and drop of dataset's attributes into report designer (dragged Toolbox's ReportViewer and created a new report).
For contracts due for renewal, I do not have any dataset to drag and drop. (?)
My "Contract" table containing the following fields:
Contract_ID INT NOT NULL,
Vendor_ID INT NOT NULL,
DateStart datetime,
DateDue datetime,
PRIMARY KEY(Contract_ID),
FOREIGN KEY (Vendor_ID) REFERENCES Vendor(Vendor_ID)
I hope I convey what I wanted to say correctly. Any help is greatly appreciated. Thanks!
telly
p.s I already an alternative in mind, which is done not really in a report way.
|
|
|
|
|
How are you creating reports ? It sounds to me like you've got to the point of needing to learn SQL.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi Graus,
Thanks for the reply.
But what is wrong with the SQL (btw, the SQL statements are used for MSSQL)? Don't mind can you say in more detail instead of just a one-liner. I really do not know where the SQL went wrong. I'm currently a beginner in SQL and VB.net but I do make an attempt in trying before asking, and learnt along the way.
I created reports using this. I followed the steps exactly (the only difference is probably the database attributes).
Meticulous advise, please? Appreciated. thanks.
telly
|
|
|
|
|
It sounds to me like you're creating reports by dragging and dropping in some tool. SQL functions like GetDate allow you to write SQL that checks a date against a known value, but you would need to write your own SQL for that, not use a tool that generates it.
I have never used the report viewer control, I didn't know it existed.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I'm assuming you use the crystal reports version that is embedded in visual studio 2005
since you already are able to display the records on a form I'm also asuming you can find the sql query needed for this
if both asumtions are correct this might be a way to do what you want:
you create a new report (add --> crystal report)
in the database expert of that report (tab data) you can select you'r database then you get the option to add a table or a command
choose command
now you can enter an sql query wich will be used to create the report
do some layout on the report as you see fit
then on you'r form do the following:
<br />
sub btnprint.click<br />
Dim rpt As New ProjectVoorblad()<br />
rpt = reconnectreport(rpt)<br />
Dim dt As New DataTable()<br />
dt = FILLDTWITHYOURSQLQUERY<br />
rpt.SetDataSource(dt) 'this will only work if there is only 1 command and 0 tables in the report <br />
crvMain.ReportSource = rpt 'crvmain = crystal reports vieuwer<br />
end sub<br />
<br />
Private Function reconnectreport(ByVal report As ReportDocument) As ReportDocument<br />
Dim connection As IConnectionInfo<br />
Dim oldServerName As String = report.DataSourceConnections(0).ServerName<br />
Dim newServerName As String = sservername<br />
Dim oldDatabaseName As String = report.DataSourceConnections(0).DatabaseName<br />
Dim newDatabaseName As String = sdbname<br />
Dim userID As String = susername<br />
Dim password As String = spass<br />
report = report<br />
' Change the server name and database in main reports<br />
For Each connection In report.DataSourceConnections<br />
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _<br />
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then<br />
' SetConnection can also be used to set new logon and new database table<br />
report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection( _<br />
newServerName, newDatabaseName, userID, password)<br />
End If<br />
Next<br />
' Change the server name and database in subreports<br />
Dim subreport As ReportDocument<br />
For Each subreport In report.Subreports<br />
For Each connection In subreport.DataSourceConnections<br />
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _<br />
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then<br />
' SetConnection can also be used to set new logon and new database table<br />
subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection( _<br />
newServerName, newDatabaseName, userID, password)<br />
End If<br />
Next<br />
Next<br />
Return report<br />
End Function<br />
the reconnectfunction reconnects you'r report to the correct database (if it changed)
if the connection to you'r database never changes you don't really need to do this
hope this helps
if you need more explenation let me know
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistakes.
|
|
|
|
|
Hi TD, thanks for the reply.
Your assumptions:
1) I use ReportViewer (am using Microsoft Visual Studio 2005 btw) from the Toolbox to create reports. I do not use Crystal Report (I just use Windows Form).
2) Do you mean the SQL select query for listing contracts due for renewal in 3 months? If so, yes I know the query.
SELECT Contract_ID<br />
FROM Contracts<br />
WHERE DateDue BETWEEN GetDate() AND DateAdd(mm, 3, GetDate())
Do you have any idea how to do a report which list contracts due for renewal in 3 months (which is not one of the database attribute)?
Previously how I created my report(drag and drop):
like this
Can you help me please? Thanks in advance.
telly
|
|
|
|
|
first sorry for the late reply but I didn't have access to the internet this weekend
for you'r problem:
I'v never used your way of creating reports but from the looks of it its some sort of spin-off from crystal reports.
If you want to continue using this way my sugestion would be to create a dummy dataset (with you'r sql in it) then before you call the report you fill the dataset with the correct data that way you can keep using this drag and drop methode
I think that with the sql query you provided you don't even have to fill the dataset it will always be correct (if the table doesn't change and the date to look from is always the current date) so you should be able to create the dataset and use it like any other
if that doesn't work I suggest looking into crystal reports it will accomplish alot more and is free (at least the one embedded in visual studio is)
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistakes.
|
|
|
|
|
Hi everyone,
Here I have a strange problem.
I am working on a console application.
I use the following code to print : Welcome
console.writeline("Welcome")
Now I want to print: "Welcome"
I want to print it with quotes. but ,
console.writeline(" "Welcome" ") gives me an error.
So, what to do to print a word with quotes??
Thanks For any help,
Dan
|
|
|
|
|
Not strange at all. How would the compiler know when " means a quote you want to print, or when it means a quote, in the usual sense ?
console.writeline("\"Welcome\"")
Assuming it works the same as C#. f not, you'll have to google to find the VB syntax.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
For VB you can use console.writeline("""Welcome""")
|
|
|
|
|
|
I have a question. I need to know if it would be better for me to use a fill by method or a binding source.
Here is what I am doing.
I have a check box and 2 combo boxes for each day of the week. The user would check the Monday check box and then choose a time of day such as 6:00PM in the from time and 10:00PM in the to time combo box. Once the user selects the times the combo boxes populate these times from a database table and sets the selected value from another table that holds the time they selected.
Can you tell me what would be better to do? Should I use a FillBy Method or a Binding Source? When I first learned VB.Net in college about 2 years ago I just wrote a query and used a data adapter. I am new to VB.NET 2005 and have very little experience in VB.
When I added the () to (BindingSource) Dim instance As BindingSource() the instances are getting a blue squigly line. Why?
Here is the code I am writing using a Binding Source.
Dim bsMonStoreSched As BindingSource()<br />
Dim bsTuesStoreSched As BindingSource()<br />
Dim bsWedStoreSched As BindingSource()<br />
Dim bsThurStoreSched As BindingSource()<br />
Dim bsFriStoreSched As BindingSource()<br />
Dim bsSatStoreSched As BindingSource()<br />
Dim bsSunStoreSched As BindingSource()<br />
<br />
' create table adapter objects<br />
Dim hoursTableAdapter As New theLessonProgramDataSetTableAdapters.tbl_hoursTableAdapter<br />
Dim schedTableAdapter As New theLessonProgramDataSetTableAdapters.tbl_store_schedTableAdapter<br />
<br />
' create data set objects<br />
Dim lpDataSet As New theLessonProgramDataSet()<br />
<br />
' create dataTables<br />
Dim dtHours, dtSched As New DataTable()<br />
<br />
' create binding source<br />
Dim bsHours As BindingSource<br />
Dim bsStoreSched As BindingSource<br />
<br />
' fill the dataTables<br />
Try<br />
hoursTableAdapter.Fill(lpDataSet.tbl_hours)<br />
schedTableAdapter.Fill(lpDataSet.tbl_store_sched)<br />
Catch err As Exception<br />
MessageBox.Show(err.Message)<br />
End Try<br />
<br />
dtHours = lpDataSet.tbl_hours<br />
dtSched = lpDataSet.tbl_store_sched<br />
<br />
' Set the binding Source for mon - sun<br />
bsMonStoreSched.DataSource = dtSched<br />
bsTuesStoreSched.DataSource = dtSched<br />
bsWedStoreSched.DataSource = dtSched<br />
bsThurStoreSched.DataSource = dtSched<br />
bsFriStoreSched.DataSource = dtSched<br />
bsSatStoreSched.DataSource = dtSched<br />
bsSunStoreSched.DataSource = dtSched<br />
<br />
' Filter the items to show results.<br />
bsMonStoreSched.Filter = "ss_day = 'Monday'"<br />
bsTuesStoreSched.Filter = "ss_day = 'Tuesday'"<br />
bsWedStoreSched.Filter = "ss_day = 'Wednesday'"<br />
bsThurStoreSched.Filter = "ss_day = 'Thursday'"<br />
bsFriStoreSched.Filter = "ss_day = 'Friday'"<br />
bsSatStoreSched.Filter = "ss_day = 'Saturday'"<br />
bsSunStoreSched.Filter = "ss_day = 'Sunday'"<br />
<br />
' fill the Mon - Sun combo boxes with the hours<br />
cboLSMonFrom.DataSource = dtHours<br />
cboLSMonFrom.DisplayMember = "h_time"<br />
cboLSMonFrom.ValueMember = "h_id"<br />
cboLSTuesFrom.DataSource = dtHours<br />
cboLSTuesFrom.DisplayMember = "h_time"<br />
cboLSTuesFrom.ValueMember = "h_id"<br />
cboLSWedFrom.DataSource = dtHours<br />
cboLSWedFrom.DisplayMember = "h_time"<br />
cboLSWedFrom.ValueMember = "h_id"<br />
cboLSThurFrom.DataSource = dtHours<br />
cboLSThurFrom.DisplayMember = "h_time"<br />
cboLSThurFrom.ValueMember = "h_id"<br />
cboLSFriFrom.DataSource = dtHours<br />
cboLSFriFrom.DisplayMember = "h_time"<br />
cboLSFriFrom.ValueMember = "h_id"<br />
cboLSSatFrom.DataSource = dtHours<br />
cboLSSatFrom.DisplayMember = "h_time"<br />
cboLSSatFrom.ValueMember = "h_id"<br />
cboLSSunFrom.DataSource = dtHours<br />
cboLSSunFrom.DisplayMember = "h_time"<br />
cboLSSunFrom.ValueMember = "h_id"<br />
<br />
' bind the list controls selected value property<br />
cboLSMonFrom.DataBindings.Add("SelectedValue", bsMonStoreSched, "ss_id")<br />
cboLSTuesFrom.DataBindings.Add("SelectedValue", bsTuesStoreSched, "ss_id")<br />
cboLSWedFrom.DataBindings.Add("SelectedValue", bsWedStoreSched, "ss_id")<br />
cboLSThurFrom.DataBindings.Add("SelectedValue", bsThurStoreSched, "ss_id")<br />
cboLSFriFrom.DataBindings.Add("SelectedValue", bsFriStoreSched, "ss_id")<br />
cboLSSatFrom.DataBindings.Add("SelectedValue", bsSatStoreSched, "ss_id")<br />
cboLSSunFrom.DataBindings.Add("SelectedValue", bsSunStoreSched, "ss_id")
|
|
|
|
|
AAGTHosting wrote: Dim bsMonStoreSched As BindingSource()
Dim bsTuesStoreSched As BindingSource()
Dim bsWedStoreSched As BindingSource()
Dim bsThurStoreSched As BindingSource()
Dim bsFriStoreSched As BindingSource()
Dim bsSatStoreSched As BindingSource()
Dim bsSunStoreSched As BindingSource()
First, let me say that you have no reason to use this many bindingsources for what your code is suggesting you're doing. One is enough.
Second, seriously, pick up a book on VB.NET for beginners. These lines mearly declare a variable that CAN hold a BindingSource object. You never actually created any BindSource objects because you're missing the New keyword in the Dim statement.
Dim bsTuesStoreSched As New BindingSource()
The problem you run into with this code is that as soon as these variables fall out of scope, the BindingSources will be destroyed. You have to declare these in class scope, not method scope.
|
|
|
|
|
The word Greeting in gives me an error; " name is not declared" how can i solve it?
Private Sub DeliveryOptions_EnterEvent(ByVal sender As System.Object, ByVal e As AxVBVoiceLib._DGetdgEvents_EnterEvent) Handles DeliveryOptions.EnterEvent
'ByVal Greeting As Object
Greeting.RemoveAll()
Greeting.InsertIndexPhrase(0, FILE_LEAVE_VM_VAP, LV_VM_TO_SEND_MSG)
|
|
|
|
|
This means you don't have a variable called "Greeting" defined anywhere in scope.
Seriously, pick up a beginners book on VB.NET. This is a very basic error caused by not knowing how to declare variables.
|
|
|
|
|
Dave is right, you really need to get up to speed on your VB
First, you have you declaration of Greeting commented out. I guess that you did that because when you didn't the .RemoveAll() and InsertIndexPhrase() methods errored out. This is probably because those methods are not standard members of the Object type but rather members of some VBVoice object type.
|
|
|
|
|
Hello all!
When I call one of my dialogues with the ShowDialog() function my application exits. Just like that. No error message or anything. I have tried catching the error but it does not help. Also, this problem occurs only on some machines, all of which have no debugger installed. Unfortunately I have no idea where to start looking for the error. Does anybody know anything I can do short of writing the thing from scratch?
Happy new year!
Volker Weichert
|
|
|
|
|
If there's no error message, odds are, there's no error. One thing springs to mind - if you have a dialog with a button defined as being the OK button, and it launches a child with an OK button defned, pushing OK will close both.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thank you for your answer.
In this case the parent form is a normal form. Also, I traced through the program and pinpointed the error to the actual ShowDialog() method. Since the dialog does not show but the application quits I guess there is an error somewhere. I just have no idea where to look for it .
Volker Weichert
|
|
|
|
|
I'm trying to write a method that loops through a form and dumps the name of all controls and the data from each control into a string, it works fine until it gets to a control that its self has controls in it, like a tabcontrol. Is there any work around so I can get this to work in a single method? The getValue(childControl) function simply uses a typeof check and returns the data of that control as a string. Any help would be appreciated.
Public Function reportApplicationState(ByVal controlList As Windows.Forms.Form.ControlCollection) As String<br />
Dim strIndent As String = ""<br />
Dim report As String = ""<br />
Dim childControl As Control<br />
For Each childControl In controlList<br />
If childControl.Controls.Count > 0 Then<br />
layoutIndent &= " "<br />
report &= childControl.Name & ControlChars.CrLf<br />
Dim nextChildControl As Control<br />
For Each nextChildControl In childControl.Controls<br />
reportApplicationState(nextChildControl.Controls)<br />
Next<br />
Else<br />
report &= layoutIndent & childControl.Name & getValue(childControl) & controlChars.CrLf<br />
End If<br />
Next<br />
Return report<br />
End Function
|
|
|
|
|
Additional info: reportApplicationState(nextChildControl.Controls) - throws exception
Exception thrown at runtime:
System.InvalidCastException was unhandled
Message="Unable to cast object of type 'ControlCollection' to type 'ControlCollection'."
Source="detailedErrorReports"
StackTrace:
at detailedErrorReports.StateReport.reportApplicationState(ControlCollection controlList) in C:\Documents and Settings\Ed\My Documents\Visual Studio 2005\Projects\detailedErrorReports\detailedErrorReports\StateReport.vb:line 12
at detailedErrorReports.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Ed\My Documents\Visual Studio 2005\Projects\detailedErrorReports\detailedErrorReports\Form1.vb:line 5
sorry about the code sample indentation
|
|
|
|
|
I'd probably rewrite this so you don't have a "nextChildControl" section. One level should be enough.
Speaking of level, I'd also change this method to take as parameters a ControlCollection AND an interger representing depth, so you can have a collection in a collection in a collection, ... Probably something like this:
Public Function reportApplicationState(ByVal controlCollection As ControlCollection, Optional ByVal childDepth As Integer = 0) As String
Dim layoutIndent As New String(" "c, childDepth)
Dim report As String = String.Empty
Dim childControl As Control
For Each childControl In controlCollection
If childControl.Controls.Count > 0 Then
report &= childControl.Name & ":" & Environment.NewLine
report &= reportApplicationState(childControl.Controls, childDepth + 1)
Else
report &= layoutIndent & childControl.Name & getValue(childControl) & Environment.NewLine
End If
Next
Return report
End Function
This is by no means tested, but you should get the idea...
|
|
|
|
|
Your right in saying only one level is needed, the inner loop was only added after i initially had problems. This works fine for all controls on the controlList passed in, but when it calls its self when it finds a control with child controls i get an error casting from the child controls to a control list even though they appear to be of the same type. Any ideas on why the cast fails would be appreciated.
|
|
|
|
|
Hi Developers
I'm looking for an Open Source Invoice Management System, which I can modify easily according to my needs....
Please let me know if you know about any good resource about it. Thanks
|
|
|
|