Try
Dim sqlpp As New SqlParameter
Dtmain = Dsmain.Tables(0).Copy
SQLT = CNN.BeginTransaction
CMD.Transaction = SQLT
CMD.Connection = CNN
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = "inscustvendmaster"
CMD.Parameters.AddWithValue("@Custname", Dtmain.Rows(0).Item("Custname"))
CMD.Parameters.AddWithValue("@Dob", Dtmain.Rows(0).Item("DOB"))
CMD.Parameters.AddWithValue("@type", Dtmain.Rows(0).Item("Type"))
Dim Myparam As SqlParameter = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
Myparam.Direction = ParameterDirection.ReturnValue
CMD.ExecuteNonQuery()
RecIDCust = CMD.Parameters("RETURN_VALUE").Value
Dim dt As New DataTable
If RecIDCust > 0 Then
dtAddress = New DataTable
If Not Dsmain.Tables(1) Is Nothing Then dtAddress = Dsmain.Tables(1).Copy
If Not dtAddress Is Nothing Then
If dtAddress.Rows.Count > 0 Then
For i = 0 To dtAddress.Rows.Count - 1
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = "InsAddressMaster"
CMD.Parameters.Clear()
CMD.Parameters.AddWithValue("@CustId", RecIDCust)
CMD.Parameters.AddWithValue("@add1", dtAddress.Rows(i).Item("Address1"))
CMD.Parameters.AddWithValue("@add2", dtAddress.Rows(i).Item("Address2"))
Myparam = New SqlParameter
Myparam = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
Myparam.Direction = ParameterDirection.ReturnValue
CMD.ExecuteNonQuery()
AddressIdCust = CMD.Parameters("RETURN_VALUE").Value
If Myparam.Value = 0 Then
Berror = True
Exit For
Else
dtContact = New DataTable
If Not Dsmain.Tables(2) Is Nothing Then dtContact = Dsmain.Tables(2).Copy
If Not dtContact Is Nothing Then
If dtContact.Rows.Count > 0 Then
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = "InscontactMaster"
For j = 0 To dtContact.Rows.Count - 1
CMD.Parameters.Clear()
CMD.Parameters.AddWithValue("@addressId", AddressIdCust)
CMD.Parameters.AddWithValue("@Contactname", dtContact.Rows(j).Item("Contactname"))
CMD.Parameters.AddWithValue("@Mobileno", dtContact.Rows(j).Item("Mobileno"))
CMD.Parameters.AddWithValue("@ZipNo", dtContact.Rows(j).Item("ZipNo"))
Myparam = New SqlParameter
Myparam = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
Myparam.Direction = ParameterDirection.ReturnValue
CMD.ExecuteNonQuery()
If Myparam.Value = 0 Then
Berror = True
Exit For
End If
Next
End If
End If
End If
Next
End If
End If
End If
If Berror = False Then
CMD.Transaction.Commit()
CNN.Close()
Return RecIDCust
Else
CMD.Transaction.Rollback()
CNN.Close()
Return 0
End If
Catch ex As Exception
Throw ex
CMD.Transaction.Rollback()
Finally
If CNN.State <> ConnectionState.Closed Then CNN.Close()
End Try
Dim sqlpp As New SqlParameter
Dtmain = Dsmain.Tables(0).Copy
SQLT = CNN.BeginTransaction
CMD.Transaction = SQLT
CMD.Connection = CNN
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = "inscustvendmaster"
CMD.Parameters.AddWithValue("@Custname", Dtmain.Rows(0).Item("Custname"))
CMD.Parameters.AddWithValue("@Dob", Dtmain.Rows(0).Item("DOB"))
CMD.Parameters.AddWithValue("@type", Dtmain.Rows(0).Item("Type"))
Dim Myparam As SqlParameter = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
Myparam.Direction = ParameterDirection.ReturnValue
CMD.ExecuteNonQuery()
RecIDCust = CMD.Parameters("RETURN_VALUE").Value
Dim dt As New DataTable
If RecIDCust > 0 Then
dtAddress = New DataTable
If Not Dsmain.Tables(1) Is Nothing Then dtAddress = Dsmain.Tables(1).Copy
If Not dtAddress Is Nothing Then
If dtAddress.Rows.Count > 0 Then
For i = 0 To dtAddress.Rows.Count - 1
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = "InsAddressMaster"
CMD.Parameters.Clear()
CMD.Parameters.AddWithValue("@CustId", RecIDCust)
CMD.Parameters.AddWithValue("@add1", dtAddress.Rows(i).Item("Address1"))
CMD.Parameters.AddWithValue("@add2", dtAddress.Rows(i).Item("Address2"))
Myparam = New SqlParameter
Myparam = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
Myparam.Direction = ParameterDirection.ReturnValue
CMD.ExecuteNonQuery()
AddressIdCust = CMD.Parameters("RETURN_VALUE").Value
If Myparam.Value = 0 Then
Berror = True
Exit For
Else
dtContact = New DataTable
If Not Dsmain.Tables(2) Is Nothing Then dtContact = Dsmain.Tables(2).Copy
If Not dtContact Is Nothing Then
If dtContact.Rows.Count > 0 Then
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = "InscontactMaster"
For j = 0 To dtContact.Rows.Count - 1
CMD.Parameters.Clear()
CMD.Parameters.AddWithValue("@addressId", AddressIdCust)
CMD.Parameters.AddWithValue("@Contactname", dtContact.Rows(j).Item("Contactname"))
CMD.Parameters.AddWithValue("@Mobileno", dtContact.Rows(j).Item("Mobileno"))
CMD.Parameters.AddWithValue("@ZipNo", dtContact.Rows(j).Item("ZipNo"))
Myparam = New SqlParameter
Myparam = CMD.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
Myparam.Direction = ParameterDirection.ReturnValue
CMD.ExecuteNonQuery()
If Myparam.Value = 0 Then
Berror = True
Exit For
End If
Next
End If
End If
End If
Next
End If
End If
End If
If Berror = False Then
CMD.Transaction.Commit()
CNN.Close()
Return RecIDCust
Else
CMD.Transaction.Rollback()
CNN.Close()
Return 0
End If
Catch ex As Exception
Throw ex
CMD.Transaction.Rollback()
Finally
If CNN.State <> ConnectionState.Closed Then CNN.Close()
End Try
No comments:
Post a Comment