Tuesday, August 23, 2011

Find.Execute() in MS Word 2007 gives a "The stub received bad data" error

Here is the solution
void FindAndReplace(ref Microsoft.Office.Interop.Word.Application WordApp, object FindText, object ReplaceText)
    {
      object MatchCase = true;
      object MatchWholeWord = true;
      object MatchWildCards = false;
      object MatchSoundsLike = false;
      object nMatchAllWordForms = false;
      object Forward = true;
      object Format = false;
      object MatchKashilda = false;
      object MatchDiacritics = false;
      object MatchAlefHamza = false;
      object MatchControl = false;
      object ReadOnly = false;
      object Visible = true;
      object Replace = 2;
      object Wrap = 1;

      

      object[] Parameters = new object[] { FindText, MatchCase, MatchWholeWord, MatchWildCards
                        , MatchSoundsLike, nMatchAllWordForms, Forward, Wrap
                        , Format, ReplaceText, Replace, MatchKashilda
                        , MatchDiacritics, MatchAlefHamza,MatchControl };
      WordApp.Selection.Find.GetType().InvokeMember("Execute", System.Reflection.BindingFlags.InvokeMethod, null, WordApp.Selection.Find, Parameters);      
    }

Tuesday, August 16, 2011

how to return id after insert ms sql


IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT

 

The insert satement should look something like this.

INSERT INTO TABLE (COLUMN1, COLUMN2, ...)
VALUES     (@COLUMN1,@COLUMN2, ...);
SELECT IDENTITY_COLUMN FROM TABLE WHERE (IDENTITY_COLUMN = SCOPE_IDENTITY())

Then in your code do something like this

int identity = Convert.ToInt32(TableAdapter.InsertMethod(value1, value2, value3));