c# - Execute Mail Merge and produce many docs. Type Mismatch error -
//instantiate worddoc , wordapp string pathdoc, datetemp = string.empty; datetime ddatetemp = new datetime(); ddatetemp = convert.todatetime(sdate); var ds = new dataset(); string textdate = ddatetemp.tostring("mm/dd/yy"); switch (msdatetype) { case "d": ssql = string.format(msquery+"'{0}'",textdate); break; case "w": ddatetemp = ddatetemp.adddays(4); datetemp = ddatetemp.month.tostring("mm") + "/" + ddatetemp.day.tostring("dd") + "/" + ddatetemp.year.tostring("yy"); ssql = msquery + " @textdate"; //ssql = msquery + " '" + textdate + "' , '" + datetemp + "'"; messagebox.show(ssql); break; case "n": ssql = msquery; break; default: break; } string test = "select * ltrfammednoshow apptdt = '06/01/2015'"; int same = string.compare(test, ssql, true); using (cn = new sqlconnection(connectionstring)) { cn.open(); using (sqlcommand command = cn.createcommand()) { command.commandtext = test; // "select top 10 * ltrfammednoshow"; // //command.parameters.add(@textdate, sqldbtype.nvarchar,15); //command.parameters[@textdate].value = textdate; //messagebox.show(command.commandtext); var adapter = new sqldataadapter(command); adapter.fill(ds); } } //set path , document of letter used merge pathdoc = mspath + "\"" + msdocument; //create new instance of word application wordapp = new microsoft.office.interop.word.application(); //add new document worddoc = wordapp.documents.add(ref omissing, ref omissing, ref omissing, ref omissing); worddoc.select(); //create mailmerge data document createdatadoc(ref wordapp, ref ds); worddoc = wordapp.documents.add(template: @"d:\clinicletters\fammed\noshow.doc"); wordapp.visible = true; worddoc.mailmerge.opendatasource(@"d:\\data.doc"); //worddoc.mailmerge.destination = wdmailmergedestination.wdsendtonewdocument; //worddoc.mailmerge.execute(ref ofalse); worddoc.mailmerge.execute(ds); //worddoc.words.last.insertbreak(microsoft.office.interop.word.wdbreaktype.wdpagebreak); //close original form document worddoc.saved = false; worddoc.close(ref ofalse, ref omissing, ref omissing); //release reference worddoc = null; wordapp = null;
i tried think of product multiple letters ( stay in same doc easier printing purpose) kepting getting type mismatch error. can help? opinions highly appreciated. in advance.
the specific error describe occurs because parameter .execute not dataset want use (ds) boolean specifies word when error occurs in merge.
difficult see beyond depends partly on createdatadoc method does.
Comments
Post a Comment