C# .NET - CSV file will not collate
Asked By Mayra on 22-Feb-11 02:00 PM
PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.Copies = 2;
printDoc.PrinterSettings.Collate = true;
The CSV page prints when the button is clicked but it will not collate.
Also, I am working on getting a button to do two things. I have it doing one thing already: When I click it it generates a file and saves it
private void GenerateRejCSV()
{
try
{
SqlCommand cmdViewRej = new SqlCommand("ViewSubmittedRejuvenateRecords", connection);
cmdViewRej.CommandType = CommandType.StoredProcedure;
SqlDataReader reader;
reader = cmdViewRej.ExecuteReader();
string sfile = "";
while (reader.Read())
{
string s1 = reader["BARRELID"].ToString() + "," + reader["SCANNEDDATE"].ToString() +
"," + reader["OAKTYPE"].ToString() + "," + reader["ROWNUMBER"].ToString() + "," + reader["USERID"].ToString() +
"," + reader["SCANNEDTIME"].ToString() + "\r\n";
sfile = sfile + s1;
}
File.WriteAllText(csvpath + textBoxRejuvenate.Text + ".CSV", sfile);
reader.Close();
}
I need it to also print the file that this generates with the same click. Is that possible?
Mohan Raj Aryal replied to Mayra on 22-Feb-11 02:25 PM

PrintDocument printDoc = new PrintDocument(); printDoc.PrinterSettings.Copies = 2; printDoc.PrinterSettings.Collate = true; The CSV page prints when the button is clicked but it will not collate. Also, I am and saves it private void GenerateRejCSV() { try { SqlCommand cmdViewRej = new SqlCommand( "ViewSubmittedRejuvenateRecords" , connection); cmdViewRej.CommandType = CommandType.StoredProcedure; SqlDataReader reader; reader = cmdViewRej.ExecuteReader(); string sfile = "" ; while (reader.Read()) { string s1 = reader[ "BARRELID" ].ToString USERID" ].ToString() + ", " + reader[ "SCANNEDTIME" ].ToString() + " \ r \ n" ; sfile = sfile + s1; } File.WriteAllText(csvpath + textBoxRejuvenate.Text + ".CSV" , sfile); reader.Close(); } I need it to also print the file that this generates with the same click. Is that possible? Yes it is can create a function PrintCSVFile() function. Within this function you can write c# code to print the file. There is a article you can see http: / / www.c-sharpcorner.com / UploadFile Drawing method as I have given the link above. keywords: SqlDataReader, WriteAllText, SqlCommand, PrintDocument, ExecuteReader, CSV file, Print, collate description: CSV file will not collate PrintDocument printDoc = new PrintDocument(); printDoc.PrinterSettings
the database specified in / / / the connection string / / / < / summary> / / / <remarks> / / / e.g.: / / / int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders"); / / / < / remarks> / / / <param name = "connectionString"> A valid connection string for a SqlConnection< / param> / / / <param name the connection string / / / using the provided parameters / / / < / summary> / / / <remarks> / / / e.g.: / / / int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24)); / / / < / remarks> / / / <param name = "connectionString"> A valid connection string for a AssignParameterValues(commandParameters, parameterValues); / / Call the overload that takes an array of SqlParameters return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, commandParameters); } else { / / Otherwise we can just call the SP without params return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName); } } / / / <summary> / / / Execute a SqlCommand (that returns no resultset and takes no parameters) against the
need of writing this line and actuly what this line do ? please explane . myCommand.CommandType = CommandType.StoredProcedure; Using this line- myCommand.CommandType = CommandType.StoredProcedure; We indicate to command object that, operation will be performaed by Stored Procedure, not by 2. set the command object so it knows / / to execute a stored procedure cmd.CommandType = CommandType.StoredProcedure; By setting the CommandType to StoredProcedure , the first parameter to the SqlCommand constructor will be stored procedure in return it will exceute StoredProc Procedure. myCommand = new SqlCommand("StoredProc"); myCommand.CommandType = CommandType.StoredProcedure; Hope this helps Welcome CommandType property is used to define whether you are using the
we are used to write code like to the parameters collection. Similar to this: SqlCommand cmd = new SqlCommand("sp_myprocedure", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@prm1", prm1)); cmd.Parameters.Add(new SqlParameter("@prm2", prm2)); / / Execute engine path for a stored procedure. When you call a sproc, you should ALWAYS use CommandType.StoredProcedure and a fully populated set of Parameter objects, rather than "EXEC spName param1 param2" and is changed". Thanks keywords: SQL Serverstored procedure, SqlParameter, SqlCommand, SQLServer, TEXT description: Commandtype Text vs Commandtype StoredProcedure we are used to write code like sp_myprocedure prm1, prm2 concatenating the parameters and returns
hi, i got this error - No overload for method dt; } } DAL public DataTable Load_Albumcat_byid(string albcategoryid) { SqlCommand cmd = new SqlCommand("Carmeltvm_sp_load_Albcategory", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@albcategoryid", albcategoryid); DataTable dt = new DataTable(); SqlDataAdapter adpt = new SqlDataAdapter(cmd); try
I need source code reference of that. after just click button event, now showing print dialog, print start it's what I wanted. thanks your reply in advance. It depends on from where you wanted to print, you can check this on how to print from browser control with and without print dialog http: / / www.ussbd.com / printhtm.html And, you could print without print dialog using print method on printdocument. . The following links does this, http: / / www
Hi give me print dialoag box for print. in my application when i press print buttion open print button go through this examples http: / / www.codeproject.com / KB / printing / simpleprintingcs.aspx http: / / www c-sharpcorner.com / uploadfile / mgold / pritingincsharp11222005040630am / pritingincsharp.aspx its really easy to print a page using a simple link on a page. Write the following: <a href = "javascript:window.print()"> Print Page< / a> When you click this link in your browser a print page will open
simple way to print C# .NET 06-Jun-13 10:05 AM Helo to EggHeadCafe Team I have an c#. In panel i have some textboxes and its values on button click i want print the values inside the panel and also i wants to see print preview as i don;t have a printer so i will check it by print preview Plz tell me step by step as searched a lot but didn't find in easy way plz tell in easy way If you want to show a print preview page before print ing any page, then you have to make a page like the one that currently is showing. Or, if you want to print a particular section of that page, like only a DataGrid , HTML table, or any other section, and you also need to preview that in a separate page before print ing, you have to create a separate print preview page to show, which is more
know of. • Right click on the diagram and select "copy to clipboard" • Get Gadwin Screen Print from http: / / forums.asp.net / t / 1190828.aspx / 1?printing+a+database+diagram and paste that work: 2, 6 — values that fail: 15, 16, 64 IF @name IS NULL BEGIN PRINT ‘WARNING! Stored Procedure was called without defined @Name parameter WARNING! ‘ + CHAR(10)+ ‘Please call one sysdiagrams) SELECT @y = name FROM AbfrageLoop WHERE Row = @cnt - do something based on the query print ‘EXEC [dbo].[Tool_ScriptDiagram2008] @Name = ‘ “ + @y + “ “ SELECT @cnt = @cnt+1 END -While Loop RETURN (-1) END diagram_id , @size = DATALENGTH(definition) FROM dbo.sysdiagrams WHERE [name] = @name IF @diagram_id IS NULL BEGIN PRINT ‘ / * *<error> Diagram name [' + @name + '] could not be found.< / error> * / ‘ END ELSE — Diagram exists BEGIN — Now with the diagram_id, do all the work PRINT ‘ / * *’ PRINT ‘<summary> Restore diagram “’ + @name + ““’< / summary> ’ PRINT ‘<generated> ’ + LEFT(CONVERT(VARCHAR(23), GETDATE(), 121), 16) + ‘< / generated PRINT ‘* / ‘ PRINT ‘ PRINT “ = = = Tool_ScriptDiagram2008 restore diagram [ ' + @name + ' ] = = = “ ‘ PRINT ‘ — If the sysdiagrams table has not been created