Object List to Dynamicly insert query

Function ObjFaturaEkle(Objfaturalar As Object, ProjeAd As String)Dim dbl As New dblibDim voi As New voilibDim insertq As String = ""Dim fatsayibasarili As Integer = 0Dim fatsayibasarisiz As Integer = 0Dim hatavar As Boolean = FalseDim kolonadlaristr As String = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TBL_FATURA'"Dim kolonlist As List(Of DataRow) = voilib.QueryDondur(kolonadlaristr)Dim faturakontrol As List(Of DataRow)Dim kolonlar As String = ""Dim valuesstr As String = ""Dim valtype As String = ""Dim faturakod As String = ""For Each obj In ObjfaturalarFor Each kl In kolonlistIf (kl(0) <> "id" And kl(0) <> "ProjeAd") Thenkolonlar = kolonlar & kl(0).ToString & ","End IfNextkolonlar = kolonlar.Substring(0, kolonlar.Length - 1)For Each kl In kolonlistIf (kl(0) <> "id" And kl(0) <> "ProjeAd" And kl(0) <> "void_islemtarihi" And kl(0) <> "aktarimdurum") ThenIf IsNothing(obj.GetType().GetProperty(kl(0).ToString).GetValue(obj)) = False Thenvaltype = obj.GetType().GetProperty(kl(0).ToString).PropertyType.ToStringIf valtype.IndexOf("String") > 0 Or valtype.IndexOf("Date") > 0 Or valtype.IndexOf("DateTime") > 0 ThenIf valtype.IndexOf("Date") > 0 Thenvaluesstr = valuesstr & "'" & voi.tarihYYYYMMDDondurDate(obj.GetType().GetProperty(kl(0).ToString).GetValue(obj).ToString()) & "',"Elsevaluesstr = valuesstr & "'" & obj.GetType().GetProperty(kl(0).ToString).GetValue(obj).ToString().Replace("'", "") & "',"End IfIf (kl(0) = "ErpKod2") Thenfaturakod = obj.GetType().GetProperty(kl(0).ToString).GetValue(obj).ToString()End IfElseIf (obj.GetType().GetProperty(kl(0).ToString).GetValue(obj).ToString() = "") Thenvaluesstr = valuesstr & "'',"ElseIf (obj.GetType().GetProperty(kl(0).ToString).GetValue(obj).ToString() = "False" Or obj.GetType().GetProperty(kl(0).ToString).GetValue(obj).ToString() = "True") Thenvaluesstr = valuesstr & "'" & obj.GetType().GetProperty(kl(0).ToString).GetValue(obj).ToString().Replace("'", "") & "',"Elsevaluesstr = valuesstr & obj.GetType().GetProperty(kl(0).ToString).GetValue(obj).ToString().Replace(",", ".") & ","End IfEnd IfEnd IfElsevaluesstr = valuesstr & "NULL,"End IfEnd IfNextvaluesstr = valuesstr.Substring(0, valuesstr.Length - 1)Tryfaturakontrol = voilib.QueryDondur("SELECT id From TBL_FATURA WHERE ProjeAd='" & ProjeAd & "' AND Matbuno='" & faturakod & "'")If (faturakontrol.Count > 0) Thenvoi.QueryCalistir("DELETE from TBL_FATURA WHERE ProjeAd='" & ProjeAd & "' AND ErpKod2='" & faturakod & "'")End Ifinsertq = "INSERT INTO TBL_FATURA(ProjeAd," & kolonlar.ToString & ") VALUES('" & ProjeAd & "'," & valuesstr & ",getdate(),'Aktarılmadı')"voi.QueryCalistir(insertq)fatsayibasarili = fatsayibasarili + 1Catch ex As Exceptionhatavar = Truevoi.Entlogyaz(faturakod, faturakod, faturakod & "Nolu fatura çekilirken Hata", "", 0)fatsayibasarisiz = fatsayibasarisiz + 1End Tryinsertq = ""kolonlar = ""valuesstr = ""faturakod = ""Nextvoi.Entlogyaz("", "", "Başarılı aktarılan Fatura Sayısı : " & fatsayibasarili & "-" & "Başarısız Aktarılan Fatura Sayısı : " & fatsayibasarisiz, "", 1)End Function

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store