Need list of columns (fields) in a SQlite table within Visual Basic - vb.net

I'm building a query application in VS 2012 in which the user drills down by sequentially selecting the Database, then Table, then Column for the search. Database and Table selection work fine. Column selection not-so-much.
Table selection is the following SQL query Command String:
Dim ThisSQLcs As String = "SELECT `name` FROM sqlite_master WHERE type = 'table';"
Similar syntax for getting Column data does not work (type = "column") because there are no column/field types in sqlite_master. I have seen suggestions in other posts that work from the CLI (.schema tablename) or something about PROGMA table_info('table_name'), but neither of those work in this VS / VB context.
Any suggestions would be appreciated.
-larry

Related

Create an SQL query to find all tables in the whole Redshift database containing a specific text string (data)

using, Tableau or Aginity I am trying to find all the Tables in Redshift Database that contain the string of word "Certified Service".
Look online and so very long codes, as I am new to SQL I couldn't see what to replace in the code to adapt it to my query, and most codes seems to give me the error "Syntax error".
I'm sorry for the repeated question, although most answers on here seem to be a few years old so not sure if anything as changed.
Again I'm very new to SQL
Thanks in advance
Try using following query to list all the table in Redshift, containing a specific text string
SELECT DISTINCT tablename FROM pg_table_def WHERE schemaname = 'public' and tablename ilike '%certified service%';
In case you want to search tbales with another sub-string, Replace certified services with your custom string and you'll get a list of all tables whose name contain that sub-string.

MS Office 12.0 Access Database Engine OLE DB Provider driver assigns different data type to text columns, compared with Jet 4 driver

Summary:
A Crystal report is connected to an Access database (amongst others), using a SQL query. One of the columns consists of an expression that is exposed in Crystal as a "TEXT [255]" field when connected to the Access database using the Jet4 DAO driver, but as "Memo" when connected using the Microsoft Office 12.0 Access Database Engine OLE DB Provider. This causes downstream problems.
Details:
I have a Crystal report which consumes data from two different MS Access databases, using separate SQL queries defined in the report. The results are then combined using a table link (a table link is similar to a table join, but operates across tables from different databases, and is processed by Crystal itself, as opposed to running server-side).
The table link is based (on the one side) on a calculated column ("ColumnToLinkOn") in the SQL query, which looks like this (anonymized):
SELECT
Column1 AS Heading1,
Column2 as Heading2,
Left(Column2,6) AS ColumnToLinkOn -- Table link based on this column
FROM NameOfTable
The data type of Column2 in Access is Short Text (as Access 2013 calls it - previously this was known as Text).
Now for the interesting bit: when the connection from Crystal to the Access database is of type Jet4 (DAO), then the data type of ColumnToLinkOn is String [255]. However, if the connection is changed to use the Microsoft Office 12.0 Access Database Engine OLE DB Provider, then Crystal picks it up as Memo (we change the connection type because we need it to work in 32 and 64 bit mode, but there is no 64 bit Jet4 driver). The problem with this is that table links cannot be based on Memo fields, so that renders the link invalid.
My question:
How can I alter the SQL query to cast the data type to a normal text field, so that it can be used in table links? According to the Access documentation, the LEFT function returns Variant (String), which I suspect causes the problem. The source column is not of type memo, so it is clearly the LEFT function that introduces the problem.
I've tried wrapping the result in CStr, like this: CStr(Left(Column2,6)) AS ColumnToLinkOn, but this has made no difference. I also found a hint that said that doing this Replace(Left(Column2,6), "", "") AS ColumnToLinkOn will help, but it didn't. Unfortunately Access also doesn't support the CAST(column AS type) syntax.
I'm using Access 2013 and Crystal Reports 2013.
Any assistance will be greatly appreciated!
If the records are distinct, you can do it like this:
SELECT DISTINCT
Column1 AS Heading1,
Column2 as Heading2,
Left(Column2,6) AS ColumnToLinkOn -- Table link based on this column
FROM NameOfTable
Access can't match on memo fields either, so it has to truncate memo fields to shorttext to find distinct elements.
Another way would be use a Crystal subreport, and link to a formula field on the subreport instead of linking to the table.

How can I link values in a text file to values in a SQL Server table?

UPDATE 2
Essentially, I'd like to pass the dataTable into SQL Server, but not actually "create it", just like a temporary thing using:
cmd.CommandText = "SELECT *
FROM table1
INNER JOIN dataTable
ON sample.name = dataTable.name"
How can I pass the dataTable from vb.net (.NET 2.0) to SQL Server in a similar fashion?
UPDATE 1
So I'm thinking maybe passing the data from the text file into a datatable and using that to compare against the SQL Server table? How would I go about doing that if at all possible?
ORIGINAL POST
I have a table in SQL Server 2012 (i.e., dbo.sample1) within the table there is a column that contains names (i.e., abc01, abc02, abc03, hijk01, hijk02...)
I ran some vb code to extract certain file names without extension from a directory on my machine (i.e., abc01, abc02...) that met certain conditions, these file names were saved on separate lines within a text file.
Is there any easier convenient way of linking ONLY the names on my text file to the ones on my table so as not to show any rows that are not on the text file? I figured I can sit and plug in a bunch of WHERE name = 'abc01'... but didn't really want to site there and do that for all of the names I have. But I'm not sure is this might even work correctly as I need to do an INNER JOIN on of 2 tables in the DB to the values in the text file.
If this is a long problem, then please point me in the right direction and I can research and move forward with it, but any help is greatly appreciated, thanks!
If the list of filenames is reasonable you can us the IN() clause:
SELECT * from XXX WHERE name IN ('abc01', 'abc02', 'abc03',...)
If the list is too long look into bulk copy up to a temp table to use with a JOIN.

How to convert Select (Transact-SQL) syntax to VB .NET

I am using VB .NET and I have a huge variable (Table A) in DataTable format. Table A has many columns.
I need to create a subset of table (class DataTable) from Table A by checking the field value in each Column from Table A.
There is a function in SQL, which matches the requirement above. It is called as SELECT (Transact-SQL). I have found the SQL description in the websites below:
http://msdn.microsoft.com/en-us/library/ms189499.aspx and
http://www.w3schools.com/sql/sql_where.asp.
My question:
What is the equivalent command in VB .NET which performs same task on DataTable?
I have checked various sources on converting the SQL command above to VB .NET. The Select Case in VB .NET works as an if condition checking.
Thank you.
Your best approach, if you need the result to also be in a DataTable, is likely to be creating a DataView:
Dim sourceTable = new DataTable()
....
Dim myView = new DataView(sourceTable, "selected = 1", "",
DataViewRowState.Current)
Dim newTable = myView.ToTable()
The second parameter is the where clause part of a SQL SELECT statement, whilst the third allows you to add sorting to the result. The final parameter allows you to select a subset of the original rows if required.
You can try the DataTable.Select method.

Access Query by form that runs SQL Server view as a backend query

I have a Access DB with SQL Server as Backend DB, all the tables in Access are linked from SQL Server. I want to create a query by form for keyword search. I am planning to have a access form such as:
Step 1: Shows a dropdown that lists all the tables in the DB, once a table is selected
Step 2: another dorpdown shows up that lists all the column names in the selected table, once a column is selected
Step 3: then a text box appears where I enter a keyword that will run a select query on the selected table with the criteria on the selected column that is entered in the text box and gives the result.
Now I have a SQL Server query to list the column names of a given table.
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE (TABLE_NAME = 'table-name')
ORDER BY ORDINAL_POSITION
I want to use this query for the second step.
I cannot understand how to connect Access QBF to run a query in SQL Server.
Should I make a view or stored procedure in SQL Server?
Can someone please tell me how to get this done.
Thank You.
There is an easy way to do this using MS Access.
If you set the row source of table select combo to:
SELECT [name] FROM msysobjects WHERE type=4;
Then add a little code:
Private Sub cboTable_AfterUpdate()
Me.cboFields.RowSource = Me.cboTable
End Sub
And set the field selection combo Row Source Type to Fields, you should get what you want.
You can link views from SQL Server to MS Access.