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",""))))
Related
Do somebody know how can i write in SQL language in Visual FoxPro a query with parameters? It doesn't work in the same way like it does in Access and I am a little bit lost here.
Thank you in advance!
Unfortunately your question is too broad to provide a simple answer.
The syntax for one query will vary from the syntax to perform a different query.
And Yes, the SQL Query syntax is likely slightly different than M$ Access.
However you can always do a Google search for: vfp sql query syntax to find specific syntax equivalents.
Note: The "WITH" parameters will be in a simple WHERE clause similar to most other SQL Query languages,
Such as WHERE Field1 = "ABC" AND Field2 = 235
but it will be using the VFP language syntax.
Also you might want to spend some time looking at the free, on-line VFP tutorial videos at: free on-line VFP tutorial videos
Specifically the one labeled: FoxPro and the SQL Language
You can visit w3schools.com to see SQL basics. It doesn't work like access, that is true, because access, which is a so called SQL database engine, has its own understanding of the SQL. VFP OTOH is closer to ANSI SQL (IOW closer to SQL Server).
You haven't specified the language you are using, but saying access, I would assume you are trying with VBA. Here is a sample in VBA (excel) using parameters:
Sub Macro1()
Dim oRecordset1 As ADODB.Recordset
Dim oConnection As ADODB.Connection
Dim oCommand As ADODB.Command
Dim oParameter1 As ADODB.Parameter
Dim oParameter2 As ADODB.Parameter
Set oConnection = New ADODB.Connection
Set oCommand = New ADODB.Command
oConnection.ConnectionString = "Provider=VFPOLEDB;Data Source=C:\Program Files (x86)\Microsoft Visual FoxPro 9\Samples\Northwind"
oConnection.Open
oCommand.ActiveConnection = oConnection
oCommand.CommandText = "select * from Orders where OrderDate >= ? and OrderDate < ?"
Set oParameter1 = oCommand.CreateParameter("start")
oParameter1.Type = adDate
oParameter1.Value = CDate("1996-08-01")
oCommand.Parameters.Append oParameter1
Set oParameter2 = oCommand.CreateParameter("end")
oParameter2.Type = adDate
oParameter2.Value = CDate("1996-10-01")
oCommand.Parameters.Append oParameter2
Set oRecordset = oCommand.Execute()
Sheet1.Range("A1").CopyFromRecordset (oRecordset)
End Sub
Note: Parameters are positional, not named.
It depends on what kind of query you're using, either using the built-in SQL engine that queries native FoxPro tables or if it's a query using an external data source.
First for the case of a native query, it's really simple. Since it's a native FoxPro instruction, you can access to every single feature out there, including variables, where you can simply put your user supplied data without worries:
LOCAL data &&This could come from user input
data = "hello world"
SELECT * FROM SomeTable WHERE Column = data &&Filtered parametrized query
The other option is to submit a SQL query for an external server to process, where the query is sent as a text string. In this case, special markers for parameters can be used, matching FoxPro variables, and in turn that would result in a parametrized query sent to the server:
LOCAL data
data = "hello world"
LOCAL hConn = SQLSTRINGCONNECT(connectionString)
SQLEXEC(hConn, "SELECT * FROM SomeTable WHERE Column = ?data", "SomeTable") &&The "?data" parametrizes the query, sending the value separate from the query itself
SQLDISCONNECT(hConn)
I have a database that contains the data as in the following picture
Notes:
Collation Database ('SQL_Latin1.General_CP1_CI_AS').
I have no right to change Collation to Araic_CI_AS.
In case you change Collation to Araic_CI_AS, the data display from the database is displayed in the new program, but the program has a problem and it appears in the old program in the form of ????? Where the old program.
I can not modify the old program because there is no source code for it.
This database is outdated and may not be modified by anyone ( Collation [rows] or Collation [databases])
When you link the database to a new standalone program through Visual Basic 2015 to use some data from the database, the following format appears as in the picture...
What I want is to display the content of the database to change the (ãßÇÆä æÂáÇÊ) sentence to the default language which is Arabic.
I hope to find a solution through the Visual Basic code and not through the amendment to the database.
Thanks to all
The problem has been solved in the process of converting the encoding characters by the following code:
Private Function conv1256(ByVal txt As String) As String
Dim dic As New Dictionary(Of String, String)
Const _1256 As String = "ÐÏÌÍÎåÚÛÝÞËÕÖØßãäÊÇáÈíÓÔÙÒæÉìÑÄÁÆøºÅñõðó¡ÜÃòö¿Âú"
Const _utf8 As String = "ذدجحخهعغفقثصضطكمنتالبيسشظزوةىرؤءئّ؛إًٌَُ،ـأٍِ؟آْ"
For i = 0 To (_1256.Length) - 1
dic.Add(_1256.Chars(i), _utf8.Chars(i))
Next i
For Each ch In txt
conv1256 &= If(dic.ContainsKey(ch), dic.Item(ch), ch)
Next
End Function
To be used this way:
MsgBox(conv1256("ÈÓãö Çááå ÇáÑøÍãä ÇáÑøÍíã"))
Good luck and thank you all
I have a table called GRN with MS Access Database
as shown below
grn_id (Autonumber)
grn_number (Text)
grn_date (Date/Time)
invoice_number (Text)
invoice_date (Date/Time)
voucher_number (Text)
supplier (Text)
I have created a data set with VB.Net Visual Studio 2012
in the data Set I have created a table adapter and a query
with the following code
SELECT grn_id, grn_number, grn_date, invoice_number, invoice_date, voucher_number, supplier
FROM grn
WHERE (grn_number = ?)
And named it as FillByGRN
In the form I have added the following code
Me.GrnTableAdapter.FillByGRN(dataTable:=Me.DocmanDataSet.grn, grn_number:=finfo.Text)
When I Run The application and Give the textfield finfo a value and click on my button to fill is is not working and stopped on the line of filling the table adapter.
Any Solution Please
Considering the exception you mentioned, you don't seem to have Jet Database Engine driver installed on your machine. Either download and install that driver, or in case you're running against Access 2010 or later, use ACE.OLEDB connection string instead of the old-school Jet.OLEDB.
The connection string looks like this:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<Access Database Path>;
Persist Security Info=False;
You can read more about OLEDB connection strings here.
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. :-)
I'm a bit puzzled here. I did a form containing a simple datagridview containing data from an MDB file. The connection was alltogether done by Visual Studios wizard so alot of stuff was created automatically. Then I databinded the textboxes to each column in the database and managed to update the database via my own command buttons such as "Update" with this code:
Me.MainTableBindingSource.EndEdit()
Me.MainTableTableAdapter.Update(Me.DBDataSet.MainTable)
Me.DBDataSet.MainTable.AcceptChanges()
This doesn't seem to work with sql. At this point, I've done everything from scratch in this order, added a datagridview and added a database connection with the wizard when connecting the datagridview to a database. Only this time around I created an SQL connection instead.
And Visual Studio created "MainTableTableAdapter", "DBDataSet", "DBDataSet.MainTable".
The SQL server is something which was installed automatically when installing Visual Studio and it does seem to work after creating the table adapter and dataset if there's data in it. In some time I plan to use an SQL Server on the internet which hosts the dataset. So I want to be able to easily edit the source.
The only thing missing now is how to add a row, delete selected row and editing selected row via my own textboxes. More like a fill-in form. Any ideas to put me in the right direction? I've tried googling it and I've found some stuff, but most of it contains stuff on how to create the datasets and etc. And I'm not sure what Visual Studio has done automatically. And I want to update everything just as easily as I did with these three lines of code when I used a local MDB file.
If it's SQL you can do something like this. Here's an example delete function:
Public Shared Function DeleteStuff(ByVal id As Integer) As Integer
Dim query As String = _
"DELETE FROM tbl_Stuff " & _
"WHERE ID_Stuff = " & id & ";"
Dim connection As SqlConnection = YourDB.GetConnection
Dim deleteCommand As New SqlCommand(query, connection)
Dim rowCount As Integer = 0
Try
connection.Open()
rowCount = deleteCommand.ExecuteNonQuery()
Catch ex As SqlException
Throw ex
Finally
connection.Close()
End Try
Return rowCount
End Function
There may be better ways, but you can always pass in SQL queries.
EDIT: Sorry this is more than three lines of code. ;)