0

Can you fix my problem? I try to insert data in table database oracle, but the data take from session array. this code controller to insert data

int[] NoId = (int[])Session["Id"];
string[] NamaBarang = (string[])Session["namaBarang"];
string[] HargaSatuan = (string[])Session["harga"];
string[] JumlahBarang = (string[])Session["jumlah"];
string[] HargaTotal = (string[])Session["total"];
string[] Diskon = (string[])Session["disc"];
string[] DPP = (string[])Session["Dpp"];
string[] PPN = (string[])Session["Ppn"];

MPMISTAX_DTLMASUK itemA = new MPMISTAX_DTLMASUK();
itemA.KD_PPN = "2";
itemA.KDUNIT = Kategori;
itemA.KODE_SUPP = "M2Z";
itemA.NOFAK = nomorFaktur;
itemA.KDFAK = kodeFaktur;
itemA.VKODECABANG = KodeMain;
item.TAHUN = TanggalFak.Year;
itemA.RETUR = "";
itemA.NMBRG = NamaBarang[0];
itemA.HRGSAT = HargaSatuan[0];
itemA.NPWP = npwpPenjual;
itemA.NODOK = "-";

dbContext.MPMISTAX_DTLMASUK.Add(itemA);
dbContext.SaveChanges();

I try using that code, but its error. I Hope you can help my problem. Thank you

4
  • What is the error ? Commented May 31, 2016 at 4:09
  • itemA.NMBRG type data is long, but session array NamaBarang[0] type data is string, and can I insert data array in table database ? Commented May 31, 2016 at 4:19
  • You will have to loop through array to insert into database. Commented May 31, 2016 at 4:38
  • Can you give me example? I don't have any idea, because I still new learning about mvc and oracle database Commented May 31, 2016 at 4:44

2 Answers 2

1

What is the datatype of

itemA.NMBRG?

if it's long please convert the NamaBarang[0] to long datatype before assigning. Like

itemA.NMBRG = (long)NamaBarang[0];

Hope this helps!!

Sign up to request clarification or add additional context in comments.

1 Comment

the datatype of itemA.NMBRG is string, same of NamaBarang[0], but the problem is datatype of itemA.HRGSAT. that is long and the HargaSatuan[0] is string. I can't convert because the string include " . " not only character. and convert to long not worked.
0

You are trying to assign string to a feild which is of type long .Parse the string to long for feild NMBRG.

itemA.NMBRG = (long)NamaBarang[0];

9 Comments

thank, that work, but you can help me, how can I Insert data array in table database?
You have to insert two arrays ?
Can you give me example with code? because I don't know how to explain that. My mind is blank. I Hope you can help me?
I have one more question ? How is that string include " . " not only character?
Strings are enclosed in double qoutes. Length of NamaBarang and HargaSatuan will be same ?
|

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.