hi,
I faced this problem when I tried to insert data into the database.

public CustomMessage SaveIssue(Issue issue)
        {
            if (issue.Id == 0) return InsertIssue(issue);
            else return UpdateIssue(issue);
        }

        public CustomMessage InsertIssue(Issue issue)
        {
            string fieldNames  = "(Sl_no,Date,NamePrdOrRep,NameOfDepartment,TitleOfProduction,TapeType,PurposeShooting,PurposePreview,QuantityOfTape,BoxNo,BoxName,TapeNo,IssueOrReturn)";

the error message is shown this line execution

string fieldValues = "Values( '" + issue.Sl_no.Replace("'", "''") + "', '" + issue.Date + "', '" + issue.NamePrdOrRep.Replace("'", "''") + "', '" + issue.Department.Replace("'", "''") + "', '" + issue.TitleOfProduction.Replace("'", "''") + "', '" + issue.TapeType.Replace("'", "''") + "', '" + issue.PurposeShooting.Replace("'", "''") + "', '" + issue.PurposePreview.Replace("'", "''") + "', " + issue.QuantityOfTape + ", '" + issue.BoxNo.Replace("'", "''") + "', '" + issue.BoxName.Replace("'", "''") + "', '" + issue.TapeNo.Replace("'", "''") + "', '" + issue.IssueOrReturn.Replace("'", "''") + "' )";            string sqlText = "INSERT INTO [Issue] " + fieldNames + fieldValues;

            dbOperations                = new DBOperations();
            CustomMessage customMessage = dbOperations.ExecuteQuery(sqlText);
            if (customMessage.MsgId == 0) customMessage.MsgText = "Successfully Saved.";
            return customMessage;
        }

Lets first clean up the sql statement so you can easily view it with the debugger and see which item is null...

string sql = string.Format("INSERT INTO [Issue] (Sl_no,Date,NamePrdOrRep,NameOfDepartment,TitleOfProduction"
            +",TapeType,PurposeShooting,PurposePreview,QuantityOfTape,BoxNo,BoxName,TapeNo,IssueOrReturn) "
            + "Values( '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8},'{9}','{10}','{11}','{12}' )"
            ,issue.Sl_no.Replace("'", "''")
            ,issue.Date
            ,issue.NamePrdOrRep.Replace("'", "''")
            ,issue.Department.Replace("'", "''")
            ,issue.TitleOfProduction.Replace("'", "''")
            ,issue.TapeType.Replace("'", "''")
            ,issue.PurposeShooting.Replace("'", "''")
            ,issue.PurposePreview.Replace("'", "''")
            ,issue.QuantityOfTape
            ,issue.BoxNo.Replace("'", "''")
            ,issue.BoxName.Replace("'", "''")
            ,issue.TapeNo.Replace("'", "''")
            ,issue.IssueOrReturn.Replace("'", "''")
            );

Now with the debugger, put a break point just above the statement, and use your mouse to inspect each of the values, and see which one is null.

If you are the creator of the issue class, I suggest setting up the properties to never return null.
// Jerry

Thanks! dear for your help, I have found that which values are null...

,issue.TapeType.Replace("'", "''") -----> show null

IssueGUI class.......
..................................
Issue issue = new Issue();
issue.Sl_no = sl_noTextBox.Text;
.........................................
.........................................
...couldn't write this line, so...
issue.TapeType = tapeTypeComboBox.Text;
........................................
........................................
........................................

IssueManager issueManager = new IssueManager();
CustomMessage customMessage = issueManager.SaveIssue(issue);

...........................
MD. Zahid Hasan
Programmer
Rtv-National Television Ltd.
Bangladesh.

That's nice trick to encode single quote.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.