Thursday, 12 June 2014

Pass DBNull.value for string and integer for dropdownlist and text value in asp.net

//Create an object

 public object ConvertToDbReadyString(string value)
    {
        if (value == "0" || value == "")
            return DBNull.Value;
        else
            return value;
    }

//Pass value with sql parameter

 SqlParameter[] pp = new SqlParameter[]
        {
            new SqlParameter("@SqlPara",ConvertToDbReadyString(tile)),//   string
            new SqlParameter("@SqlPara1",ConvertToDbReadyString(name)), //integer
            new SqlParameter("@SqlPara2",ConvertToDbReadyString(age)),//integer
            new SqlParameter("@SqlPara3",ConvertToDbReadyString(que)),//string
        };
sqlCommon cmd;
      cmd.ExecuteNonQuery(CN, CommandType.StoredProcedure, "insertdata", pp);

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...