If this is the code that is throwing that exception then it would appear that
Label12.Text
is empty.
How I came to this conclusion ..
The error message clearly states that
Quote:
Column 'nofak' cannot be null
So I searched for
nofak
and found it in these two lines
simpan = "INSERT INTO tbbeli(nofak,tanggal,kodesup,totalitem,totalbayar) VALUES (@p1,@p2,@p3,@p4,@p5)"
simpan1 = "INSERT INTO tbdetailbeli(nofak,kodebarang,jumlah) VALUES (@p6,@p7,@p8) "
Because you have correctly used parameterised queries it is easy to spot that parameter
@p1
or parameter
@p6
must be at fault (
if this is the code that is throwing the exception).
So I searched for where
@p1
or
@p2
are being initialised
.Parameters.Add("p1", OdbcType.VarChar, 20).Value = Label12.Text
and
.Parameters.Add("p6", OdbcType.VarChar, 20).Value = Label12.Text
Of course if it is CommandText
ubah
that is throwing the exception it means that you have a record on your table that was inserted before the constraint on
nofak
was added - i.e. you have corrupt data. You will either have to delete that row or correct it manually.
To ensure you get better answers in future, always let us know which line of code is throwing the exception.
If you are not sure how to use the debugging tools in Visual Studio here is a starting point
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[
^]