Posts

Showing posts with the label sql server

C# Use a stored procedure to fill a dataset/table

When you fill a DataSet/Table in C# you use a SQL Data Adapter. The code for this is geared towards a SQL SELECT statement. However I'm not a big fan of raw SQL in my code so I found a way to use a stored procedure instead. public static DataTable GetTable() { DataTable dt = null; try { using( SqlConnection connection = new SqlConnection( "your connection string" ) ) { using( SqlDataAdapter sda = new SqlDataAdapter() ) { using( SqlCommand command = new SqlCommand( "your stored procedure", connection ) ) { command.CommandType = CommandType.StoredProcedure; // this line needs to be added for every parameter the SP expects command.Parameters.AddWithValue( "parametere value", paramValue ); sda.SelectCommand = command; dt = new Da...

C# execute a stored procedure using SQL Server

Below we have some code that opens a connection to a database using a connection string then executes a stored procedure. This obviously needs to be placed in some method or class. You will need to add your own connection string and parameter values. try { using( SqlConnection connection = new SqlConnection("some connection string" ) ) { using( SqlCommand command = new SqlCommand( "stored procedure name", connection ) ) { command.CommandType = CommandType.StoredProcedure; // this line needs to be added for every parameter the SP expects command.Parameters.AddWithValue( "parametere value", paramValue ); connection.Open(); // based on the what the SP does, call the execute non query, execute scalar, or execute reader method command.ExecuteNonQuery(); } } } cat...

Sql Server Reporting Services export to PDF in Landscape

So I have found a need to create ssrs reports in pdf format. Some of these reports contain a lot of data. So I needed to layout the page in landscape format. Sadly there is no page layout settings in srrs (once again Crystal wins but that is another story). So to achieve the same thing you will need to change the settings of the page. Open the properties of the report and set the width=29cm and height=21cm. These are the settings for landscape. Now you have a lot of extra room to move things around. I also found to maximize the report you can get the width of the report to about 22.86cm. So to summarize width=29cm (11.41") height=21cm (8.27") report data=27.30cm (10.75")