0

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;
        }

Edited by mike_2000_17: Fixed formatting

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by neeks
0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.