Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

sql server query output to json file automatically

// TODO: Add your code here
                string query = "SELECT TOP 5 [BusinessEntityID],[NationalIDNumber],[OrganizationNode],[OrganizationLevel] FROM [HumanResources].[Employee]";
                string connectionSql = "Server=(local);Database=AdventureWorks2016CTP3;Integrated Security=true";
                StreamWriter myFile = new StreamWriter(@"c:sqlfileCSharp.txt");
                using (SqlConnection connection = new SqlConnection(connectionSql))
                {
                    SqlCommand command = new SqlCommand(query, connection);
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            myFile.WriteLine(String.Format("{0}, {1}, {2}, {3}", 
                            reader["BusinessEntityID"], reader["NationalIDNumber"], reader["OrganizationNode"], reader["OrganizationLevel"]));
                        }
                    }
                    catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                            Dts.TaskResult = (int)ScriptResults.Failure;
                        }
                    finally
                        {
                            reader.Close();
                            myFile.Close();
                        }
                }
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity play animation on click 
Csharp :: Get replace normal text from word document in C# 
Csharp :: winforms combobox get selected text 
Csharp :: c# Write a program to reverse an array or string 
Csharp :: convert json date to datetime c# 
Csharp :: linq select 
Csharp :: get list of constants in class c# 
Csharp :: change physics material unity 
Csharp :: c# how to check the minimum and maximum of numbers 
Csharp :: how to add arrays in c# 
Csharp :: datetime show 24 hour format c# 
Csharp :: datatable select c# 
Csharp :: unity animation length 
Csharp :: js if empty then 0 
Csharp :: while loop in c# 
Csharp :: wpf dispatcher timer is inaccurate 
Csharp :: c# how to refresh input field 
Csharp :: set time on audio source unity 
Csharp :: how to solo squad in fortnight 
Csharp :: c# yes no cancel dialog with icons 
Csharp :: public controller script unity 3d 
Csharp :: transform.lookat 2d 
Csharp :: visual studio 2019 problem create new .net framework class library 
Csharp :: how to system func bool unity 
Csharp :: conditional middleware .net core 
Csharp :: how to detach the camera from the player after death unity 
Csharp :: c# add field to expando object 
Csharp :: use string[] args c# 
Csharp :: using Tls12 .net 3.5 
Csharp :: unity mix gradient colors 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =