retrieve value from sql server and passing it to string to write it into txt file using VB .NET - vb.net

I am retrieving some data from sql server and trying to write it to a text file, I am getting error in retrieving and passing it to variable Could you please help me in this.

You don't give a lot of detail regarding the error. Assuming your query is working and returning data to the table, Streamwriter.Write(dt) won't return the data in the table, it will return the name of the table or something like that. to get all the data you need to either loop through the rows and columns and print each one as you like or use dt.WriteXML(myIOStream), obWRiter.(myIOstream). You can also try streamwriter.write(dt.writexml()). I haven't tried anything out so you'll need to work on the code.

Related

In ADF use a lookup output as a parameter for an Oracle Query

I'm a complete beginner with Azure Data Factory and I'm struggling to set a parameter using a lookup output, and then use the parameter within my query to import data.
I'm using an Azure SQL database as the source for the lookup and an Oracle database as the source for the copy data
My lookup query works ok and my copy data query works without a parameter so I know I'm part way there, but I'm struggling with the parameter part.
My lookup details are below with the output query
The copy data query is below with the lookup activity as the parameter added but as you can see it's not correct.
I'm not sure if I should be using the lookup as the parameter or if I should be using a parameter with the value generated from the lookup. In which case I have no idea how to do this.
I'm also pretty sure the parameter in the query needs some work as even hardcoding a parameter doesn't seem to work.
If anyone can help to get this working I'd be very grateful.
There doesn't seem to be much help with turning lookups into parameters on the internet.
Thanks in advance for any help anyone can give.
Try enclosing the lookup output as follows. Select column from table where rowstamp> '#{activity('Lookup1').output.firstrow.RowStamp}'

Why do i keep getting a parameter error in my sql update?

I have been trying to use SQL with PYQT4 to update an access database with information a user has inputted into my program. I don't want to update all of the records just a specific record and a specific amount of columns (5 out of the 10 columns). however, I keep getting an error that reads:
"pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Microsoft Access
Driver] Too few parameters. Expected 6. (-3010) (SQLExecDirectW)')"
I can't seem to resolve it.
Here is my code:
SelectDatabase.execute('UPDATE Order_Table SET DateDue=(dateDueString), TimeDue=(timeDueString), PaymentType=(paymentExp), Paid=(paidExp), Customer_ID=(customerExp) WHERE OrderLine_ID=(orderlineExp)')
The values inside the brackets are variables that I have created and I am trying to call upon them, I have proof checked them multiple times, including spell checking them and I can't find a problem in that regard.
If anyone has any ideas or needs more information please let me know.
I have managed to figure out the problem. I was trying to use a variable within my SQL which once I had formatted differently worked straight away this is what I changed it to.
SelectDatabase.execute('UPDATE Order_Table SET DateDue=?, TimeDue=?, PaymentType=?, Paid=?, Customer_ID=? WHERE OrderLine_ID=?', dateDueString,timeDueString,paymentExp,paidExp,customerExp,orderlineExp)
This way by changing the values to unknowns inside the SQL procedure and referencing them in order after the edit allowed for the string values of the variables to be found and the correct columns to be edited.
Thank-you for trying to help.
Well i guess you need create your stored procedure in SQL first with all parameters and then simply call it.
Exec dbo.mYParameter 'timeDueString','paymentExp','paidExp','customerExp','orderlineExp'

Querying a pass through query Acess

I'm looking how to run a local query with date filters on a saved pass-through queries in Access. I'm trying to leverage the pass through query as basically a View in my Access database... the local query is constructed dynamically in VBA, and intended to be a clean way to filter my pass through query. I'd like to avoid creating another pass through query, or altering the original, every time i run my Sub Procedure.
My problem is that the normal access date filter format #m/d/yyyy# doesn't seem to work. I've tried both altering the date format as well in the pass through query with 1. Convert(varchar(12),p.startDate,101); 2. Convert(date,p.StartDate,101);
but neither will work when the pass through query is queried against locally.
Does anyone know how to do this?
UPDATE - I just checked and Access is reading the field as Text... does anyone know how it can read it as a date? As i mentioned the CONVERT functions don't seem to be working to do this
In a passthru you MUST use the backend's syntax. If the BE is SQL Server then I'd use a syntax like this:
WHERE DocDate = '2015-03-17'

SSIS Variable SQL command for ADO.net source

While this seems like a basic problem, I've been ripping my hair out FOR DAYS trying to get an efficient solution to this.
I have a lookup table of values on a server that I read from and assemble into a string using a C# Script task. I write this string into a variable that I want to pass in as my WHERE parameters inside a large SQL query on a ADO.NET data source (from a different server which I only have read access to) in my data flow. For example, this string would just be something like
('Frank', 'John', 'Markus', 'Tom')
and I would append that as my WHERE clause.
I can't read from a variable directly for an ADO.NET data source AND I can't use the 'Expression' property to set my SQL either as my SQL query is over 4000 characters. I could use an Execute SQL Task to run my query, load the results into a recordset and I assume, then loop through the recordset but that's extremely inefficient.
What would be the best way to do this? My end goal is to put these results inside a table on the first server.
You could try to set up Script Component as source - variables and strings inside scripts can be longer than 4000 characters so you can fit your query inside.
Setup your component similar to this article: http://beyondrelational.com/modules/2/blogs/106/posts/11119/script-componentsource-part1.aspx
In this one you have example how to fetch data using ExecuteReader and put it to output of script component: http://beyondrelational.com/modules/2/blogs/106/posts/11124/ssis-script-component-as-source-adonet.aspx In this one you have instructions how to aquire connection properly: http://www.toadworld.com/platforms/sql-server/b/weblog/archive/2011/05/30/use-connections-properly-in-an-ssis-script-task
By joining this pieces of information you should be able to write your source Script Component which can fetch data using any length dynamically constructed query.
Good luck :)
You can do a simple select statement to return a list of values that will include ('Frank', 'John', 'Markus', 'Tom'). So your select would return :
Name
----------
Frank
John
Markus
Tom
Then, in SSIS, use a Merge Join Component (that will act as a INNER JOIN) instead of a where clause in your main query.
This is the cleaniest way to achieve what you want.

Create delimited string from a row in stored procedure with unknown number of elements

Using SQL Server 2000 and Microsoft SQL Server MS is there a way to create a delimited string based upon an unknown number of columns per row?
I'm pulling one row at a time from different tables and am going to store them in a column in another table.
A simple SQL query can't do anything like that. You need to specify the fields you are concatenating.
The only method that I'm aware of is to dynamincally build a query for each table.
I don't recall the structure of MSSQL2000, so I won't try to give an exact example, maybe someone else can. But there -are- system tables that contain table defintions. By parsing the contents of those system tables you can dynamically build the necessary query for each source data table.
TSQLthat writes TSQL, however, can be a bit tricky to debug and maintain :) So be careful how you structure everything...
Dems.
EDIT:
Or just do it in your client application.