locked
INSERT INTO RRS feed

  • Question

  • User-1031608939 posted

    Hi,

    I am using VS2010 - Window Form. When I save into Access database, I using OleDBCommand. The sqlcommand is INSERT INTO tblName VALUES(all values). How if some of the values are empty? It show error message "Type mismatch". How should do if value empty?

    Thanks.

    Tuesday, January 18, 2011 4:52 AM

Answers

  • User-1199946673 posted

    I am using VS2010 - Window Form
     

    In that case, next time, ask your questions here because thes forums are intended for ASP.NET related questions only

    if some of the values are empty?

    VALUES ('x', Null, 'y')

    Or when using parametrized queries:

    Command.Parameters.AddWithValue("Name", System.DbNull.Value)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 18, 2011 7:58 AM

All replies

  • User-1412735316 posted

    you may choose following syntax

    insert into (column1,column2,column5) values(value1,value2,value5)

    it will work if ignored column allows null value.


    Tuesday, January 18, 2011 5:05 AM
  • User82239924 posted

    Hai,

    You need to specify the columns which has non-empty data to be inserted.

    Let me assume, you have 3 columns in the table, if u want insert only two filed data(ie column1,column3) and column2 is empty, then,

    Try this,

    insert into tblName(column1, column3) values('test','test')



    Tuesday, January 18, 2011 5:07 AM
  • User1867929564 posted

    In mdb,allow zero length to yes where require.
    If you hv 5 col then write as usual,
    insert into tblname (col1,col2,col3,col4,col5) values (@col1,@col2,@col3,@col4,@col5)

    Only ensure there is no datatype mismatch,like if you hv int  datatype say col2 then @col2 should be int and you pass 0 or null.

    Tuesday, January 18, 2011 7:04 AM
  • User-1199946673 posted

    I am using VS2010 - Window Form
     

    In that case, next time, ask your questions here because thes forums are intended for ASP.NET related questions only

    if some of the values are empty?

    VALUES ('x', Null, 'y')

    Or when using parametrized queries:

    Command.Parameters.AddWithValue("Name", System.DbNull.Value)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 18, 2011 7:58 AM