0

I have a simple user interface for an inventory database. The operation will be insert into, edit existing, view data grid, etc....There are a total of 4 fields for the inventory. The insert statement I am using works but if one of the entries does not have a value then it shows an error when trying to insert.

" Data type mismatch in criteria expression "

command.CommandText = "insert into Inventory(SerialNumber,PartNumber,ROnumber,Location) 
    values ('" + txtPart.Text + "','" + txtSerial.Text + "','" +
    txtRO.Text + "','" + txtLocation.Text + "')";

I assume it is because the code needs a value for each field so how do I get around this issue?.

6
  • Are all this numbers of data type string in the database table? If not, I think you dont need the single-quotes enclosing the variables.. also if any of your fields does not have data you can then pass null values (assuming the fields are nullable in the table) Commented Jan 4, 2016 at 1:11
  • make sure the field is not empty? Commented Jan 4, 2016 at 1:11
  • Ha! @ Webster,,,you sellin' tickets ? Commented Jan 4, 2016 at 1:15
  • @ vmachan..No, they would be alpha-numeric actually. I will try that one Commented Jan 4, 2016 at 1:16
  • So how do I tell it that it would be a null value ? Commented Jan 4, 2016 at 1:19

1 Answer 1

1

Actually when you trying to use this query you have said the First Parameter is SerialNumber and then PartNumber and when you are passing its reverse.

command.CommandText = "insert into Inventory(SerialNumber,PartNumber,ROnumber,Location) 
                            values ('" + txtPart.Text + "','" + 
                                         txtSerial.Text + "','" + 
                                         txtRO.Text + "','" + 
                                         txtLocation.Text + "')";

Due to this reason the fields you are entering have different size May be part number is bigger in size instead of SerialNumber or vice versa. So you should change it to

command.CommandText = "insert into Inventory(SerialNumber,PartNumber,ROnumber,Location) 
                            values ('" + txtSerial.Text + "','" + 
                                         txtPart.Text + "','" + 
                                         txtRO.Text + "','" + 
                                         txtLocation.Text + "')";
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you,,,yes I guess when I have them reversed it would cause a problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.