Hi,
I was tried to save data using ajax but always get the error message "SqlException: Invalid column name 'Nama_Obat'.",
I was not save column name "Nama_Obat" but that error always appears.
Any help could be appreciate.
Controller
[HttpPost]
public JsonResult SavePenjualanDataObat([FromBody] PenjualanObatModel penjualanObat)
{
int i = 0;
using (SqlConnection con = new SqlConnection(this._configuration.GetConnectionString("Db_Klinik")))
{
using (SqlCommand cmd = new SqlCommand("spAddDataObat", con))
{
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@No_Penjualan", penjualanObat.No_Penjualan);
cmd.Parameters.AddWithValue("@ID_Pelanggan", penjualanObat.ID_Pelanggan);
cmd.Parameters.AddWithValue("@ID_Karyawan", penjualanObat.ID_Karyawan);
cmd.Parameters.AddWithValue("@ID_Obat", penjualanObat.ID_Obat);
cmd.Parameters.AddWithValue("@Stock", penjualanObat.Jumlah);
cmd.Parameters.AddWithValue("@Harga", penjualanObat.Harga);
cmd.Parameters.AddWithValue("@Total_Bayar", penjualanObat.Total_Bayar);
i = cmd.ExecuteNonQuery();
}
}
return Json(i);
}
Store Procedure
CREATE PROCEDURE [dbo].[spAddDataObat]
-- Add the parameters for the stored procedure here
@No_Penjualan varchar(12),
@ID_Pelanggan varchar(12),
@ID_Karyawan varchar(12),
@ID_Obat varchar(12),
@Stock int,
@Harga int,
@Total_Bayar int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Insert Into Tbl_Detail_Penjualan_Obat
(
No_Penjualan,
ID_Pelanggan,
ID_Karyawan,
ID_Obat,
Stock,
Harga,
Total_Bayar
)
Values
(
@No_Penjualan,
@ID_Pelanggan,
@ID_Karyawan,
@ID_Obat,
@Stock,
@Harga,
@Total_Bayar
)
END