I'm loading a sql script up to an SSMS 2008 add-in like so:
' create a new blank document
ServiceCache.ScriptFactory.CreateNewBlankScript(Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptType.Sql)
' insert SQL statement to the blank document
Dim doc As EnvDTE.TextDocument = CType(ServiceCache.ExtensibilityModel.Application.ActiveDocument.Object(Nothing), EnvDTE.TextDocument)
doc.EndPoint.CreateEditPoint().Insert(_Output.ToString())
Is there a way to automatically execute the statement as well?
Thanks,
Mark
In SSMS 2008 R2 it would look like this:
doc.DTE.ExecuteCommand("Query.Execute");
I looked around he object model and could not find the 'execute' method - but there must a way of doing this...
But thinking slightly outside the box, you could do this.
// Set the active document
doc.DTE.ActiveDocument.Activate();
// Press F5 - which calls Execute.
SendKeys.Send("{F5}");
Okay, its a hack, but it might get you over the problem for now. :-)
Related
In Microsoft Access 2016, I would like to click somewhere and start typing SQL of new query right away. But the shortest way to start typing SQL (which I found so far) is:
Select menu Create > Query Design.
In Show Table window, press Close button.
Switch to SQL view.
Start typing SQL.
Too cumbersome. Can be the above steps 1–3 reduced to a shorter procedure? Did I overlook some command?
The fastest I can do is to put commands for steps 1 and 3 to Quick Access Toolbar and then I can for example do Alt+5, Esc, Alt+6. But this still only executes steps 1–3.
The function below creates or alters a simple placeholder query, opens it in Design View, switches to SQL View with its text highlighted, and then deletes the text.
Use the function as the RunCode action of a macro and add the macro to the Quick Access Toolbar. Then you can click that icon and start typing your SQL.
Public Function NewQuery()
Const cstrQueryName As String = "USysQuery0"
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSql As String
strSql = "SELECT Date() AS Today;"
Set db = CurrentDb
For Each qdf In db.QueryDefs
If qdf.Name = cstrQueryName Then
Exit For
End If
Next
If qdf Is Nothing Then
Set qdf = db.CreateQueryDef(cstrQueryName)
End If
qdf.SQL = strSql
qdf.Close
DoCmd.OpenQuery cstrQueryName, acViewDesign
DoCmd.RunCommand acCmdSQLView
DoCmd.RunCommand acCmdDelete
End Function
Option 1: deal with it.
By default, Access doesn't support anything faster than this.
Option 2: create a macro in your Access database to automate the task, and bind this to a key combination
You could write a macro to automate command bar actions, and bind that macro to a shortcut. I currently don't have time to look up the required commands but am certain it's possible.
Option 3: buy a plugin
There are plugins out there that immediately go to SQL view, support having the SQL and results on the same pane, have syntax highlighting, etc.
An example of such a plugin is Access SQL editor (I'm not affiliated in any way)
Option 4: Create your own.
Writing your own SQL editor that's better than what Access offers by default is very simple, because Access offers very little by default.
You can start off with a form with a textbox that takes the SQL, a save button, an execute button (requires a little VBA), and a subform that displays the query results. Then you already have something that allows you to open it and start typing right away.
While waiting for better answer, I created an AutoHotKey solution – a keyboard shortcut (restricted only to Access) to perform the above steps in English language version of Microsoft Access 2016:
SendMode Input ; // Choose mode of sending keystrokes
#IfWinActive, ahk_class OMain ahk_exe MSACCESS.EXE ; // Only in scope of MS Access app
+^n:: ; // Routine for Ctrl+Shift+N starts
Send !cqd ; // Run "Query Design" menu command
WinWaitActive,Show Table ahk_class #32770 ; // Wait for "Show Table" window
Send {Esc}!jqwq{End}{Left}{Space} ; // Send the rest of the keys
Return
#IfWinActive ; // end of #IfWinActive section
After pressing Ctrl+Shift+N and waiting a bit*, a new query window is open in SQL view and I can start typing SQL.
*) Sometimes, MS Access can be really slow on keyboard shortcuts accessing the ribbon and on switching from query Design View to SQL View.
I'm very new to using VBA within but what I need to do is simply delete all of the records in a table.
I have first created a module and have the following code within it:
Function DeleteRecords()
DoCmd.RunSQL "DELETE * FROM [7 FUF]"
End Function
I then create a macro which has one command, RunCode.
The Function Name that is passed to this command is DeleteRecords(). When I start to type in to the function name section, it does suggest DeleteRecords, so I'm confident it's seeing the function.
When running the macro, I get the error
The expression you entered has a function name that Microsoft Access
can't find
Any ideas what I'm doing wrong?
Actually the problem is not from the function. I believe your module and your function have the same name hence a conflict. If they do, make sure you change the module's name to something else like: DeleteRecordsMod. It is a known and common issue in access. Also make sure the function is publicly accessible. In your code, you don't really need * for delete everything
DoCmd.RunSQL "DELETE FROM [7 FUF]"
Delete Documentation - Vba - Microsoft
Can't find function issue - vba
You may also want to consider bypassing a macro entirely, and doing something like:
CurrentDB.Execute "DELETE * FROM [table]"
Or
Create a DELETE query and store it in the DB, then do a DoCmd.OpenQuery
I'm using visual studio 2010 to create a report, the data is being used from a SQL database
One particular set of data is being returned as integers instead of text, therefore I want to be able to do a statement where if the integer is 1 then set it as "Random" if 2 then set it as "Question" for example
I've tried the following but been unsuccessful
=Replace(Fields!new_IssueType.Value,"1","Issue")
=Replace(Fields!new_IssueType.Value,"2","Complaint")
=Replace(Fields!new_IssueType.Value,"3","FM Complaint")
=Replace(Fields!new_IssueType.Value,"4","Rejected")
I'm new to creating these expressions so I apologise if this question is a simple fix.
Try using this code:
=IIF(Fields!new_IssueType.Value = "1","Issue",IIF(Fields!new_IssueType.Value = "2","Complaint",IIF(Fields!new_IssueType.Value="3","FM Complaint",IIF(Fields!new_IssueType.Value="4","Rejected",""))))
WP8, VS12, & C#
I've started creating an app which allows me to store relational data in a local database using LINQ to SQL.
What I'd like to do next is be able to update the existing data...I would click an icon in the appbar and be taken to the previously saved data so I could update it.
I've looked on msdn... Local database for Windows Phone, and I would like to know if the following code I see at section Using the database > Updating data is valid given my LINQ to SQL set-up. If so, how do I go about adding this code to allow updating?
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
//Call base method
base.OnNavigatedFrom(e);
//Save changes to the database
toDoDB.SubmitChanges();
}
If anyone could point to a working example or help me hook up the ability to update data, I would be grateful.
Much Thanks,
k
Yhello, dunno if you still working on your project but I've got a solution for you.
From your site (msdn), here what I found :
First, query the database for the object that is to be updated. Then, modify the object as desired. Finally, call the SubmitChanges method to save the changes to the local database.
So, you need to query your db (example from my own VB.net code)
Dim monContact = From contact As Authentification In bddGLI.TableAuth Select contact
Execute the query and get the result in a collection
Dim resultCollection = New ObservableCollection(Of Authentification)(monContact)
Run through this collection with a ForEach loop and modify your object
For Each elem As Authentification In resultCollection
elem.Mail = txtEmail.Text
elem.Nom = txtNom.Text
elem.Prenom = txtPrenom.Text
Next
And don't forget to save your db
bddGLI.SubmitChanges()
Now, how to check if you really updated your data ?
Where I create my db, i inserted some data test in my table
Using db As New GeoLiveInfoDataContext(GeoLiveInfoDataContext.DBConnectionString)
If db.DatabaseExists() = False Then
db.CreateDatabase()
Dim contact As New Authentification
With contact
.Nom = ""
.Prenom = ""
.Mail = ""
End With
db.TableAuth.InsertOnSubmit(contact)
db.SubmitChanges()
End If
End Using
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh286408(v=vs.105).aspx
Go to C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v8.0\Tools\IsolatedStorageExplorerTool
SHIFT + right clic => open prompt here
ISETool.exe ts xd {ID APP HERE FROM MANIFEST } {PATH}
Don't forget to install your app on the emulator or device (not debugging)
Now at your path, you have a .sdf which can be open with SQL server Compact Edition.
Do this command before and after updating and check the difference.
Use Sqlight -- Here is a great example http://code.msdn.microsoft.com/wpapps/Using-Sqlite-with-WP8-52c3c671
The important thing in updating the data in the database is, that you handle with the same object which results the query from database and don't copy it. You can pass the object from the query results to other objects or functions but make sure that it is still the same object on the heap. Just in this case the SubmitChanges works. I did it the first time wrong and copied it for the page object and then passed it back and the SubmitChanges didn't work.
this one is the screenshot on the visual basic report. as you can see it starts at august then december then february but it i already group by it on the access which is this.
this is a query in the access im not sure if i did the right thing but i is already ordered by the earliest .
here is the sql code from the ms access
SELECT MonthName(Month([Date_sold])) & ' ' & Year([Date_sold]) AS Month_Sold, Sum(tblSell.Total_Price) AS Total_Earnings, Sum(tblSell.Quantity_Bought) AS Total_Medicine_Sold, tblSell.Generic_name, tblSell.Brand_Name
FROM tblSell
GROUP BY MonthName(Month([Date_sold])) & ' ' & Year([Date_sold]), tblSell.Generic_name, tblSell.Brand_Name, Year([Date_sold]), Month([Date_sold])
ORDER BY Year([Date_sold]), Month([Date_sold]);
in short is it doesnt order by on my report on the visual basic it should show february first like the one on ms access but it shows august which is different.
Order by, I believe, gets over written by the reports Order By property in the Data tab, on the property sheet. Either set it there or make sure it is empty. Then set the reports properties like this:
Me.OrderBy = "[SomeField], [AnotherField]"
Me.OrderByOn = True
EDIT:
All Microsoft products allow developers access to a development environment using a language called VBA (Visual Basic for Applications). You can use this language to write programs and macros to enhance products. Take a look here, although it's a bit old it may still be relevant: http://visualbasic.about.com/od/learnvba/l/aa030803b.htm
For you, you will need to add the code I suggested to the OnLoad event of the report. To do this:
Open Access.
Open your report in Design View.
On the left hand side, you should see a tab called Property Sheet
Select the Event Tab
in the OnLoad event, click the "..." (ellipsis) button
This will bring up the VBA code.
Add This:
Private Sub Report_Load()
Me.OrderBy = "[SomeField], [AnotherField]"
Me.OrderByOn = True
End Sub
Try that and see if it works.
The reason why is it not sorting (I am having this same problem at work doing some shipment order reports) is because the code is not reading the date. It will list them aplhabetically because it is a text field and not a short date. I just went to the parameters and was able to fix it there.