Asynchronous didn't work in multiple Task - vb.net

I want to make my program working asynchronously, but i got stuck in some part.
This is my main Sub, this will call Function ProsesData in loop, i got problem in my ProsesData Function.
Module Main
Sub Main()
Proses()
End Sub
Async Function Proses() As Task
Dim busOtomasi As New BusOtomasiSample
Dim dtProses As New DataTable
Dim strMessage As String = ""
Try
Dim tasks = New List(Of Task(Of Tuple(Of String, DataRow)))()
dtProses = busOtomasi.GetListProsesNotDone(strConn)
If dtProses.Rows.Count > 0 Then
For i = 0 To dtProses.Rows.Count - 1
Dim k = i
tasks.Add(ProsesData(dtProses.Rows(k), dtProses.Rows(k)("isAktelFinishProses")))
Next
For Each taskAwait In Await Task.WhenAll(tasks)
If taskAwait.Item1 = "success" Then
ExportExcel(taskAwait.Item2)
strMessage = "Data Otomasi Sample " & IIf(IsDBNull(taskAwait.Item2("param_strKcpCd")), taskAwait.Item2("param_strKcuCd").ToString, taskAwait.Item2("param_strKcpCd").ToString) & " Sudah Selesai Di Proses." & vbCrLf & "Data dapat di download di CAIS dan dibuka dengan password " & taskAwait.Item2("strPassword").ToString & "."
EmailNotification(strMessage, taskAwait.Item2("strEmail").ToString)
End If
Next
Console.ReadLine()
End If
Catch ex As Exception
EmailError("Modul Main" & vbCrLf & ex.ToString)
End Try
End Function
End Module
When It hit function AktivitasTeller.Main(dr) , it will run only one line after that apps will stoped without entering exception.
ProsesData()
Async Function ProsesData(ByVal dr As DataRow, ByVal isAktelFinishProses As Integer) As Task(Of Tuple(Of String, DataRow))
Try
If isAktelFinishProses = 0 Then
Dim result = Await Task.Run(Function() AktivitasTeller.Main(dr))
If result.ToString = "Success" Then
ProsesDataAA(dr)
Return Tuple.Create("success", dr)
Else
Console.WriteLine("Task AT Failed")
Return Tuple.Create("failed", dr)
End If
Else
ProsesDataAA(dr)
Return Tuple.Create("success", dr)
End If
Catch ex As Exception
EmailError("Modul Proses Data" & vbCrLf & ex.ToString)
Return Tuple.Create("failed", dr)
End Try
End Function
AktivitasTeller.Main()
Module AktivitasTeller
Async Function Main(ByVal dataRowAktel As DataRow) As Task(Of String)
Dim strConn As String = GetConn(Conn.eOperasional)
Dim busOtomasi As New BusOtomasiSample
Dim bitPlusKCP As Boolean = False
Dim strcabang As String = ""
Dim datediff As Integer = 0
Try
Dim tasks = New List(Of Task(Of String))()
busOtomasi.UpdateIsAktelFinishProses(strConn, 2, dataRowAktel("intIDProses"))
datediff = GetMonthDifference(dataRowAktel("param_datPeriodeAwal"), dataRowAktel("param_datPeriodeAkhir"))
If dataRowAktel("param_strKcpCd").ToString = "" Then
bitPlusKCP = True
strcabang = dataRowAktel("param_strKcuCd").ToString
Else
strcabang = dataRowAktel("param_strKcpCd").ToString
End If
busOtomasi.DeleteDataAktel(strConn, dataRowAktel("intIDProses").ToString)
For j = 0 To datediff
Dim k = 0 + 1
tasks.Add(AddAktelToSQL(dataRowAktel("intIDProses"), strcabang, CDate(dataRowAktel("param_datPeriodeAwal")).AddMonths(j), CDate(dataRowAktel("param_datPeriodeAwal")).AddMonths(datediff + k).AddDays(-1), bitPlusKCP))
Next
Dim t As Task = Task.WhenAll(tasks).ContinueWith(Sub() GET_CITIZENSHIP_DESC(dataRowAktel("intIDProses")), Sub() busOtomasi.UpdateIsAktelFinishProses(strConn, 1, dataRowAktel("intIDProses")))
Await t
If t.Status = TaskStatus.RanToCompletion Then
Return "Success"
Else
Return "Failed"
End If
Catch ex As Exception
Return "Failed"
End Try
End Function
Public Function GetMonthDifference(ByVal startDate As DateTime, ByVal endDate As DateTime) As Integer
Dim monthsApart As Integer = 12 * (startDate.Year - endDate.Year) + startDate.Month - endDate.Month
Return Math.Abs(monthsApart)
End Function
Async Function AddAktelToSQL(ByVal idProses As Integer, ByVal strCbg As String, ByVal tglAwal As Date, ByVal tglAkhir As Date, ByVal bitPlusKCP As Boolean) As Task(Of String)
'Dim tblAktelLog As New DataTable
Dim strConn As String = GetConn(Conn.eOperasional)
Dim objBusOtomasi_Script As New BusOtomasiSample
Dim DtTblSaving As New DataTable
Dim DtTblChecking As New DataTable
Dim DtTblDeposito As New DataTable
Dim DtTblRupa2 As New DataTable
Dim dtCekDeposito, dtCekSaving, dtCekChecking, dtCekRupa As New DataTable
Try
'RUPA
dtCekRupa = objBusOtomasi_Script.CekRupaBulanAtSudahProses(strConn, idProses, tglAwal.Month, tglAwal.Year, strCbg, bitPlusKCP)
If dtCekRupa.Rows.Count = 0 Then
DtTblRupa2.Clear()
DtTblRupa2 = await GetDtTbleRupa(idProses, tglAwal, tglAkhir, strCbg, bitPlusKCP)
objBusOtomasi_Script.BulkCopyRupaRupa(strConn, DtTblRupa2)
End If
'DEPOSITO
dtCekDeposito = objBusOtomasi_Script.CekBulanAtSudahProses(strConn, idProses, tglAwal.Month, tglAwal.Year, "DEPOSITO", strCbg, bitPlusKCP)
If dtCekDeposito.Rows.Count = 0 Then
DtTblDeposito.Clear()
DtTblDeposito = await GetDtTbleDeposito(idProses, tglAwal, tglAkhir, strCbg, bitPlusKCP)
objBusOtomasi_Script.bulkCopyAktTel(strConn, DtTblDeposito) 'import Deposito
End If
Return "Success"
Catch ex As Exception
'objBusOtomasi_Script.DelAktelbyID(strConn, idProses)
EmailError(ex.ToString)
Finally
strConn = Nothing
End Try
End Function
Async Function GetDtTbleDeposito(ByVal idProsesAktel As Integer, ByVal TglAwal As Date, ByVal TglAkhir As Date, ByVal KdCbg As String, ByVal FlagPlusKCP As Boolean) As Task(Of DataTable)
Dim strDWH As String
Dim objOraConn As New OracleConnection(GetConn(Conn.DWH))
Dim objOraComm As New OracleCommand
Dim objDtTableDeposito As New DataTable
Dim oraAdapter As OracleDataAdapter
Try
strDWH = "select * from ***"
Await objOraConn.OpenAsync()
oraAdapter = New OracleDataAdapter(objOraComm)
objDtTableDeposito = New DataTable
oraAdapter.Fill(objDtTableDeposito)
objOraConn.Close()
Catch ex As Exception
EmailError(ex.ToString)
End Try
Return objDtTableDeposito
End Function
Async Function GetDtTbleRupa(ByVal idProsesAktel As Integer, ByVal TglAwal As Date, ByVal TglAkhir As Date, ByVal KdCbg As String, ByVal FlagPlusKCP As Boolean) As Task(Of DataTable)
Dim strDWH As String
Dim objOraConn As New OracleConnection(GetConn(Conn.DWH))
Dim objOraComm As New OracleCommand
Dim objDtTableRupa2 As New DataTable
Dim oraAdapter As OracleDataAdapter
Try
strDWH = "select * from *** "
Await objOraConn.OpenAsync()
oraAdapter = New OracleDataAdapter(objOraComm)
objDtTableRupa2 = New DataTable
oraAdapter.Fill(objDtTableRupa2)
objOraConn.Close()
Catch ex As Exception
EmailError(ex.ToString)
End Try
Return objDtTableRupa2
End Function
Private Sub GET_CITIZENSHIP_DESC(ByVal idProses As Integer)
Dim strConn As String = GetConn(Conn.eOperasional)
Dim strDWH As String
Dim objOraConn As New OracleConnection(GetConn(Conn.DWH))
Dim objOraComm As New OracleCommand
Dim objDtTableDeposito As New DataTable
Dim oraAdapter As OracleDataAdapter
Dim dtData, dtListCust, dtResult As New DataTable
Dim busOtomasi As New BusOtomasiSample
Try
strDWH = "select * from ** "
dtListCust = busOtomasi.GetCisFromAktel(strConn, idProses)
If dtListCust.Rows.Count > 0 Then
For i = 0 To dtListCust.Rows.Count - 1
objOraConn.Open()
objOraComm = New OracleCommand(strDWH, objOraConn)
oraAdapter = New OracleDataAdapter(objOraComm)
dtData = New DataTable
oraAdapter.Fill(dtData)
If dtData.Rows.Count > 0 Then
dtResult.Merge(dtData.Copy)
End If
objOraConn.Close()
Next
busOtomasi.BulkCopyCustomerAktel(strConn, dtResult)
End If
Catch ex As Exception
EmailError(ex.ToString)
End Try
End Sub
End Module
What should i do to make this work

Related

getting data from mysql database by using thread in vb.,net

I'm trying to get data from database but I got an error:
There is already an open DataReader associated with this Connection
which must be closed first
what I did is the following codes:
1: I have a module that contains the following sub:
Public Function CheckServerConn() As Boolean
Try
_ServerConnStr = New MySqlConnection(My.Settings.DbPath)
If _ServerConnStr.State = ConnectionState.Open Then
_ServerConnStr.Close()
End If
If _ServerConnStr.State = ConnectionState.Closed Then
_ServerConnStr.Open()
Return True
End If
Catch ex As Exception
MsgBox("Check The Conn " & ex.Message, Me_MsgInfoStyle, Me_MsgCaptionStr)
Return False
End Try
#Disable Warning BC42353 ' Function doesn't return a value on all code paths
End Function
2: I have this subroutine in class called "ClsMySql":
'GetData
Public Sub GetData(ByVal SqlStr As String, ByVal xDt As DataTable, ByVal xPar() As MySqlParameter)
Using xCmd As New MySqlCommand() With {
.CommandType = CommandType.Text,
.CommandText = SqlStr,
.Connection = _ServerConnStr,
.CommandTimeout = 5000000
}
If xPar IsNot Nothing Then
For i As Integer = 0 To xPar.Length - 1
xCmd.Parameters.Add(xPar(i))
Next
End If
Using xDa As New MySqlDataAdapter(xCmd)
xDa.Fill(xDt)
End Using
xDt.Dispose()
End Using
End Sub
3: I have a class for the table that have the following method:
Public Sub MySql_Get_Daf()
xClsMySql = New ClsMySql
Dim SqlStr As String = "SELECT RegID,RegType, tblregs1.`RegRef`,`RegDate`, COUNT(`RegdID`) AS xCount
,IF(COUNT(`RegdID`) =3,'Ok','Error') AS xResult FROM tblregs1
INNER JOIN tblregs2 ON tblregs2.RegRef = tblregs1.RegRef
WHERE `RegType` = 'Daf'
GROUP BY tblregs1.`RegRef`
ORDER BY COUNT(`RegdID`) ASC"
Dt_Get_Daf = New DataTable()
xClsMySql.GetData(SqlStr, Dt_Get_Daf, Nothing)
End Sub
Public Sub MySql_Get_Qbd()
xClsMySql = New ClsMySql
Dim SqlStr As String = "SELECT RegID,RegType, tblregs1.`RegRef`,`RegDate`, COUNT(`RegdID`) AS xCount
,IF(COUNT(`RegdID`) =3,'Ok','Error') AS xResult FROM tblregs1
INNER JOIN tblregs2 ON tblregs2.RegRef = tblregs1.RegRef
WHERE `RegType` = 'Qbd'
GROUP BY tblregs1.`RegRef`
ORDER BY COUNT(`RegdID`) ASC"
Dt_Get_Qbd = New DataTable()
xClsMySql.GetData(SqlStr, Dt_Get_Qbd, Nothing)
End Sub
Public Sub MySql_Get_All()
Dim xThread As Thread = New Thread(Sub() MySql_Get_Daf())
Dim xThread2 As Thread = New Thread(Sub() MySql_Get_Qbd())
xThread.Start()
xThread2.Start()
End Sub
when I call MySql_Get_All by a button it gives me the next error:
There is already an open DataReader associated with this Connection
which must be closed first
can anybody tell me what's the wrong here

Pass multiple Value to class from function

i have 2 class 1 is get ms access data and another class for sql acsess.
i want to pass acsess class function value to sql class and assign it to sql class varible.curruntly i can assign only 1 varible.
Public Class connectionclass
Dim provider As String = "provider=Microsoft.ACE.OLEDB.12.0;data source=|DataDirectory|"
Dim database As String = "serverdata.accdb"
Public connstring As String = provider & database
Public myconnection As New OleDbConnection(connstring)
Public Function data1()
Dim x As String
Dim y As String
Dim u As String
Dim p As String
Try
myconnection.Open()
Dim getdata As New OleDbCommand("select * from server", myconnection)
Dim reader As OleDbDataReader = getdata.ExecuteReader
While reader.Read
x = reader.Item("sname")
y = reader.Item("dbase")
u = reader.Item("username")
p = reader.Item("password")
Return (x)
End While
myconnection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
End Class
2nd class
ublic Class datbaseconnect
Public obj1 As New connectionclass
Dim returnvalue As String
Dim X = obj1.data1
Dim y = ""
Dim u = ""
Dim p = ""
Public SQLCon As New SqlConnection With
{.ConnectionString =
"Server=" & x & ";
DataBase=" & y & ";
user ID=" & u & ";
password=" & p & ";
Trusted_Connection=false;
"}
End Class
Tuples are a quick and easy way to return multiple data values in a single variable without having to create a whole new class to hold the individual values.
Public Function data1() As Tuple(Of String, String, String, String)
Dim x As String
Dim y As String
Dim u As String
Dim p As String
Try
myconnection.Open()
Dim getdata As New OleDbCommand("select * from server", myconnection)
Dim reader As OleDbDataReader = getdata.ExecuteReader
While reader.Read
x = reader.Item("sname")
y = reader.Item("dbase")
u = reader.Item("username")
p = reader.Item("password")
Return New Tuple(Of String, String, String, String)(x, y, u, p)
End While
myconnection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
When calling this function it will return data like:
Dim returnedData = data1()
Finally, you simply call the function like:
WorkWithData(returnedData)
I wasn't able to include your own second class as I didn't see a function in there.
Public Sub WorkWithData(incomingData As Tuple(Of String, String, String, String))
Debug.Print(incomingData.Item1)
Debug.Print(incomingData.Item2)
Debug.Print(incomingData.Item3)
Debug.Print(incomingData.Item4)
End Sub

VB.Net freezing when adding 10000+ rows to SQL from list

I am running a RESTful API service which gets data from a server as a JSON string. Around 20000 rows are being selected.
Dim js As New JavaScriptSerializer()
Dim prodlist As List(Of Product) = js.Deserialize(Of List(Of Product))(JSONreturn)
The 20000 rows are populated in the list prodlist. Checked the count and manually verified the list.
I need to insert these rows in a client machine. However, while inserting the rows, it freezes or stops after inserting around 600-700 rows. Below is the code I am using for inserting.
For Each item As Product In prodlist
Dim SPName As String = "someSPname"
With connectionstring
.Clear()
.Parameters("#itemnumber", SqlDbType.VarChar, ParameterDirection.Input, , item.itemnumber
.Parameters("#itemtype", SqlDbType.VarChar, ParameterDirection.Input, , item.itemtype)
.Parameters("#DESCRIPTION", SqlDbType.VarChar, ParameterDirection.Input, , item.DESCRIPTION)
.Execute(SPName)
End With
Next
No error is thrown. It just freezes after inserting roughly 600-700 rows everytime.
Bulk insert is not an option. How do I resolve this?
UPDATE : Adding connection class. Pretty sure there is no issue with this :
Public Class ConnectionClass
Public ReadOnly Property ConnectionString() As String
Get
Return GetConfiguration()
End Get
End Property
Public Sub Parameters(ByVal param_name As String, ByVal type As SqlDbType, ByVal direction As ParameterDirection, Optional param_size As Int32 = Nothing, Optional param_value As Object = Nothing)
Dim sqlParam As SqlParameter = Nothing
Try
sqlParam = New SqlParameter(param_name, type)
sqlParam.Size = param_size
sqlParam.Direction = direction
sqlParam.Value = param_value
Lstparam.Add(sqlParam)
Finally
If sqlParam IsNot Nothing Then
sqlParam = Nothing
End If
End Try
End Sub
Public Sub Execute(ByVal strSpName As String, Optional ByVal Type As CommandType = CommandType.StoredProcedure)
Try
sqlcmd = New SqlCommand()
sqlcmd.Connection = connection
''Setting the timeout to 50 mins as setup in the previous application
sqlcmd.CommandTimeout = 3000
If transaction IsNot Nothing Then
sqlcmd.Transaction = transaction
End If
sqlcmd.CommandType = Type
sqlcmd.CommandText = strSpName
For Each argument As SqlParameter In Lstparam
sqlcmd.Parameters.Add(argument)
Next
For introw As Integer = 0 To sqlcmd.Parameters.Count - 1
If sqlcmd.Parameters.Item(introw).ParameterName.Contains("Parameter") Then
sqlcmd.Parameters.Item(introw).ParameterName = String.Empty
End If
Next
sqlcmd.ExecuteNonQuery()
Catch ex As Exception
Throw
End Try
End Sub
Public Sub Clear()
ClearParameters()
Lstparam.Clear()
End Sub
Public Sub ClearParameters()
If Not sqlcmd Is Nothing Then
Do Until sqlcmd.Parameters.Count = 0
sqlcmd.Parameters.Clear()
Loop
End If
End Sub
Public Function GetConfiguration() As String
Dim sbConnectionString As New StringBuilder
With sbConnectionString
.Append("Data Source=")
.Append(ServerName)
.Append(";")
.Append("Initial Catalog =")
.Append(DatabaseName)
.Append(";")
.Append("User ID =")
.Append(UserName)
.Append(";")
.Append("Password =")
.Append(UserPassword)
End With
Return sbConnectionString.ToString()
End Function
Public Function CreateClientConnection() As SqlConnection
Dim connectionString As String
Try
connectionString = GetConfiguration()
Dim substrings() As String = connectionString.ToUpper.Split(";")
Dim substrings1() As String = connection.ConnectionString.ToUpper.Split(";")
If Not (connection.State = ConnectionState.Open) Then
connection.ConnectionString = connectionString
connection.Open()
ElseIf Not (Trim(substrings(0)) = Trim(substrings1(0))) Then
If connection IsNot Nothing Then
connection.Dispose()
End If
connection.ConnectionString = connectionString
connection.Open()
End If
Return connection
Catch ex As Exception
If connection IsNot Nothing Then
connection.Dispose()
End If
Throw ex
End Try
End Function
End Class

How to get a constructor for a Public class to run

I have a Public class with a Public Shared Dictionary in vb.net. The constructor does not seem to be running. I have a breakpoint in the constructor which does not break. Also when I make a database update, the new values do not show up in the dictionary.
Public Class SkywalkerPolicy
Public Shared CustomPolicies As Dictionary(Of String, String)
Shared Sub New()
CustomPolicies = New Dictionary(Of String, String)
Dim bvin As String = String.Empty
Dim title As String = String.Empty
Dim poldescr As String = String.Empty
Dim dtResult As New DataTable("Result")
dtResult.Locale = System.Globalization.CultureInfo.InvariantCulture
Dim request As New DataRequest
request.Command = "sky_PolicyDictionary_s"
request.CommandType = CommandType.StoredProcedure
request.Transactional = False
Dim result As DataSet
result = SqlDataHelper.ExecuteDataSet(request)
If Not result Is Nothing Then
If result.Tables.Count() > 0 Then
dtResult = result.Tables(0)
For Each row In dtResult.AsEnumerable
bvin = row.Item(1)
title = row.Item(0)
poldescr = row.Item(2)
If CustomPolicies.ContainsKey(title) Then
CustomPolicies(title) += poldescr
Else
CustomPolicies.Add(title, poldescr)
End If
Next
End If
End If
End Sub
End Class
When I access the dictionary, any changes I've made to the data do not show up.
Dim pol As String = SkywalkerPolicy.CustomPolicies("Orders and Shipping Details")
Does anyone have any suggestions as to how I can get the constructor to work?
Or should I have an additional Sub which duplicates initializing the dictionary before I use it?
Thanks
I have a workaround with an Update routine which I call just before accessing the dictionary. But I am still unclear why I can't step through the constructor. So if anyone can answer the original question, I would appreciate an update. Thank you.
Public Class SkywalkerPolicy
Public Shared CustomPolicies As Dictionary(Of String, String)
Shared Sub New()
CustomPolicies = New Dictionary(Of String, String)
Dim bvin As String = String.Empty
Dim title As String = String.Empty
Dim poldescr As String = String.Empty
Dim dtResult As New DataTable("Result")
dtResult.Locale = System.Globalization.CultureInfo.InvariantCulture
Dim request As New DataRequest
request.Command = "sky_PolicyDictionary_s"
request.CommandType = CommandType.StoredProcedure
request.Transactional = False
Dim result As DataSet
result = SqlDataHelper.ExecuteDataSet(request)
If Not result Is Nothing Then
If result.Tables.Count() > 0 Then
dtResult = result.Tables(0)
For Each row In dtResult.AsEnumerable
bvin = row.Item(1)
title = row.Item(0)
poldescr = row.Item(2)
If CustomPolicies.ContainsKey(title) Then
CustomPolicies(title) += poldescr
Else
CustomPolicies.Add(title, poldescr)
End If
Next
End If
End If
End Sub
Public Shared Sub UpdateDictionary()
CustomPolicies.Clear()
Dim bvin As String = String.Empty
Dim title As String = String.Empty
Dim poldescr As String = String.Empty
Dim dtResult As New DataTable("Result")
dtResult.Locale = System.Globalization.CultureInfo.InvariantCulture
Dim request As New DataRequest
request.Command = "sky_PolicyDictionary_s"
request.CommandType = CommandType.StoredProcedure
request.Transactional = False
Dim result As DataSet
result = SqlDataHelper.ExecuteDataSet(request)
If Not result Is Nothing Then
If result.Tables.Count() > 0 Then
dtResult = result.Tables(0)
For Each row In dtResult.AsEnumerable
bvin = row.Item(1)
title = row.Item(0)
poldescr = row.Item(2)
If CustomPolicies.ContainsKey(title) Then
CustomPolicies(title) += poldescr
Else
CustomPolicies.Add(title, poldescr)
End If
Next
End If
End If
End Sub
End Class

DBNull value for parameter is not supported. Table-valued parameters cannot be DBNull

I am currently trying to pass a two table value parameters from a .net application to a database.
The error that I am getting is
DBNull value for parameter '#StageNotes' is not supported. Table-valued parameters cannot be DBNull.
I have checked that the parameter value is not null when I pass it, and the error that I get is not a sqlException, rather just a general Exception that passes this error back
The parameters are declared like so
Dim stageNotesparamTable2SQL As New SqlParameter("#StageNotes", SqlDbType.Structured)
Dim responsesParamTable2SQL As New SqlParameter("#Responses", SqlDbType.Structured)
and the values are assigned like this
Dim responseTable = ResponsesToDt()
responsesParamTable2SQL.Value = responseTable
Dim stageTable = StageNotesToDt()
stageNotesparamTable2SQL.Value = stageTable
The parameters are declared in the stored proc like this
#StageNotes [App].[StageNotesTableType] READONLY,
#Responses [app].QuestionResponseTableType READONLY,
When debugging I see that the stageNotesparamTable2SQL.Value is showing that there is a datatable in there and has the data so it is definitely not null.
I would be grateful if anyone could help me with this.
thanks
-- edit ---
Protected Function ResponsesToDt() As DataTable
Dim dt As New DataTable()
dt.Columns.Add("CheckId", GetType(Integer))
dt.Columns.Add("QuestionId", GetType(Integer))
dt.Columns.Add("AnswerId", GetType(Integer))
dt.Columns.Add("StaffNumber", GetType(String)).MaxLength = 15
Dim dictValues = _dicOfControlsAndValues.Where(Function(x) x.Key.Contains("ddl_Stage_"))
For Each item In dictValues
Dim ddlIdBreakDown = item.Key.ToString().Split("_").ToList
Dim checkid As Integer = item.Key.ToString().Split("_").Last
Dim questionId As Integer = Convert.ToInt16(ddlIdBreakDown(4))
Dim answerId As Integer = Convert.ToInt16(item.Value)
Dim staffNumber As String = GetLoggedOnStaffNumber()
dt.Rows.Add(checkid, questionId, answerId, staffNumber)
Next
Return dt
End Function
Protected Function StageNotesToDt() As DataTable
Dim dt As New DataTable
dt.Columns.Add("CheckId", GetType(Integer))
dt.Columns.Add("StageId", GetType(Integer))
dt.Columns.Add("StageNotes", GetType(String))
dt.Columns.Add("ModifiedDate", GetType(String))
Dim dictValues = _dicOfControlsAndValues.Where(Function(x) x.Key.Contains("textArea_Stage"))
For Each item In dictValues
Dim stageNote As String = String.Empty
Dim ddlIdBreakDown = item.Key.ToString().Split("_").ToList
If String.IsNullOrEmpty(item.Value.ToString()) Then
stageNote = "."
Else
stageNote = item.Value.ToString()
End If
Dim checkid As Integer = item.Key.ToString().Split("_").Last
Dim stageId As Integer = Convert.ToInt16(ddlIdBreakDown(2))
Dim stageNotes As String = stageNote
Dim modifiedDate As DateTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")
dt.Rows.Add(checkid, stageId, stageNotes, modifiedDate)
Next
Return dt
End Function
-- edit 2 --
DAL.ExecCommand("[App].[usp_SaveCheckDetails]", "",
checkIdParam,
userIdParam,
caseNoteParam,
checkNoteParam,
checkCompletedParam,
CheckFeedbackSentToUserId,
stageNotesparamTable2SQL,
responsesParamTable2SQL)
Then the DAL im having to call.
The DAL is a shared repo that Im not able to edit at the moment:
Public Function ExecCommand(ByVal spName As String, ByVal connStringName As String, ByVal ParamArray SPParms() As SqlClient.SqlParameter) As Boolean
Dim SqlConnection As New SqlConnection
Dim sqlCommand As New SqlClient.SqlCommand
Dim returnCode As Boolean = False
Try
If connStringName <> "" Then
SqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings(connStringName).ConnectionString
Else
SqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
End If
sqlCommand.CommandType = CommandType.StoredProcedure
sqlCommand.CommandText = spName
For Each p As SqlParameter In SPParms
If p.Direction <> ParameterDirection.Output Then
If Not p.Value.GetType() = GetType(Integer) Then
If p.Value.ToString() = "" OrElse p.Value = Nothing Then
p.Value = DBNull.Value
End If
End If
End If
sqlCommand.Parameters.Add(p)
Next
sqlCommand.Connection = SqlConnection
SqlConnection.Open()
sqlCommand.ExecuteNonQuery()
returnCode = True
Catch sqlEx As SqlException
HelpersErrorHandling.WriteAppLogEntry(Me.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().ToString, sqlEx)
Catch ex As Exception
If Not ex.Message.ToString().Contains("Thread was being aborted") Then
HelpersErrorHandling.WriteAppLogEntry(Me.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().ToString, ex)
End If
Finally
Try
sqlCommand.Parameters.Clear()
sqlCommand.Dispose()
SqlConnection.Close()
SqlConnection.Dispose()
Catch ex As Exception
HelpersErrorHandling.WriteAppLogEntry(Me.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().ToString, ex)
End Try
End Try
Return returnCode
End Function