Click here to Skip to main content
15,886,100 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi All
I am working on C# windows application where print button is there if I click print button the printer path in .ini file when I am trying to run it shows error
below I m giving the code

private void btnPrinter_Click(object sender, EventArgs e)
{
 private printcon pObj = new printcon() //Here "printcon" is a class file//
 private OdbcConnection connPrt = new OdbcConnection();
 connPrt = new OdbcConnection(pObj.connection());   //Format of the        initialization string does not conform to specification starting at index 0.//
 PrintDocument doc = new PrintDocument();
 doc.PrinterSettings.PrinterName = Convert.ToString(connPrt);
 doc.PrintPage += this.doc_PrintPage;
 PrintDialog dlgSettings = new PrintDialog();
 dlgSettings.Document = doc;
 doc.Print();
}

If it is possible please help

Thanks & Regards
Indrajit Dasgupta
Posted
Updated 12-Oct-11 18:46pm
v2
Comments
Pravin Patil, Mumbai 13-Oct-11 0:50am    
What is the error...?
IndrajitDasgupat 14-Oct-11 1:10am    
connPrt=new OdbcConnection(pObj.connection());
The Error is Below---
Format of the initialization string does not conform to specification starting at index 0.
Firo Atrum Ventus 13-Oct-11 1:06am    
1. Typo in new printcon()
2. There's no need to declare local variable private (no one can read them anyway)
3. Can you please show the code in printcon class?
sandesh.mumbai 13-Oct-11 1:22am    
just post the error msg also so we can get better idea about where it is having problem. As per code it looks ok just not getting why u r using this
doc.PrintPage += this.doc_PrintPage;
lukeer 13-Oct-11 3:00am    
The actual printing is done in PrintPage event handler. The handler is called by the PrintDocument.

We cannot hep from that code:
C#
private printcon pObj = new printcon() //Here "printcon" is a class file//
private OdbcConnection connPrt = new OdbcConnection();
connPrt = new OdbcConnection(pObj.connection());   //Format of the        initialization string does not conform to specification starting at index 0.
We do not know what printcon.connection is returning as a connection string - you haven't shown us that. And that is what the ODBC system is complaining about.

Run you program in the debugger. Put a breakpoint on the "connPrt = new OdbcConnection..." line, and step into the pObj.connection method. You should be able to work out what the problem is from there.
 
Share this answer
 
Refer this article, might help
Print Windows Forms w/o using API[^]
 
Share this answer
 
your call to printcon() while creating object is returning wrong value may be because of that u r call using pObj is not fall under OdbcConnection object please put breakpoint at instance of printcon & see the return value type.


private printcon pObj = new printcon() //Here "printcon" is a class file//
///put breakpoint on above line then chk for value type


private OdbcConnection connPrt = new OdbcConnection();
connPrt = new OdbcConnection(pObj.connection());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900