locked
Warning_726_Variable 'returnstring' is used before it has been assigned a value. A null reference exception could result at runtime. \DAL\Inserts.vb_24_75_DAL RRS feed

  • Question

  • User-83679056 posted

    Imports System.Data.Sql
    Imports System.Data.SqlClient
    Public Class Inserts


    Public Shared Function Sp_Upd_UserName(ByVal UserID As String, ByVal UserName As String, ByVal Email As String) As String
    Try
    Connect.Connect()
    Dim cmd As SqlCommand
    Dim dtb As DataTable
    dtb = New DataTable
    Dim rdr As SqlDataReader
    Dim returnstring As String
    cmd = New SqlCommand
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Connection = Connect.Con
    cmd.CommandText = "SP_UPD_EMAIL_USERNAME"
    cmd.Parameters.AddWithValue("@UserId", UserID)
    cmd.Parameters.AddWithValue("@UserName", UserName)
    cmd.Parameters.AddWithValue("@UserEmail", Email)
    rdr = cmd.ExecuteReader()
    dtb.Load(rdr)
    For i = 0 To dtb.Columns.Count - 1
    returnstring = dtb.Rows(0).Item(i).ToString & vbNewLine & returnstring

    Next
    Return returnstring


    Connect.Disconnect()
    Catch ex As Exception
    End Try

    End Function

    Public Shared Function Sp_Upd_UserInfo(ByVal UserID As String, _
    ByVal UserName As String, _
    ByVal UserLastName As String, _
    ByVal PHONE1 As String, _
    ByVal PHONE2 As String, _
    ByVal DOB As Date, _
    ByVal COUNTRYID As Integer, _
    ByVal CITYID As Integer, _
    ByVal ADRES As String, _
    ByVal SEXID As Integer
    ) As String


    '
    Try
    Connect.Connect()
    Dim cmd As SqlCommand
    Dim dtb As DataTable
    dtb = New DataTable
    Dim rdr As SqlDataReader
    cmd = New SqlCommand
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Connection = Connect.Con
    cmd.CommandText = "SP_UPD_USERINFO"

    cmd.Parameters.AddWithValue("@USERID", UserID)
    cmd.Parameters.AddWithValue("@USERNAME", UserName)
    cmd.Parameters.AddWithValue("@USERLASTNAME", UserLastName)
    cmd.Parameters.AddWithValue("@USERPHONENUMBER", PHONE1)
    cmd.Parameters.AddWithValue("@USERPHONENUMBER2", PHONE2)
    cmd.Parameters.AddWithValue("@USERDOB", DOB)
    cmd.Parameters.AddWithValue("@COUNTRYID", COUNTRYID)
    cmd.Parameters.AddWithValue("@CITYID", CITYID)
    cmd.Parameters.AddWithValue("@ADDRESSSTREET", ADRES)
    cmd.Parameters.AddWithValue("@USERSEXID", SEXID)
    rdr = cmd.ExecuteReader
    Connect.Disconnect()


    Catch ex As Exception

    Return ex.Message

    End Try

    End Function

    '@UserID uniqueidentifier,
    '@OrdWebSite varchar(500),
    '@OrdTrackingId varchar(50),
    '@OrdDeliveryId int,
    '@Eta Datetime,
    '@PurchaseDate Datetime,
    '@NameOnCreditCard varchar(256),
    '@Notes text,
    '@CreateUserId Uniqueidentifier

    Public Shared Function SP_INS_NEW_ORD(ByVal UserID As String, _
    ByVal OrdWebSite As String, _
    ByVal OrdTrackId As String, _
    ByVal OrdDeliveryID As String, _
    ByVal OrdEta As String, _
    ByVal PurchaseDate As DateTime, _
    ByVal NameOnCreditCard As String, _
    ByVal Notes As String, _
    ByVal CreateUserId As String) As String
    Try
    Connect.Connect()
    Dim cmd As SqlCommand
    Dim dtb As DataTable

    Dim rdr As SqlDataReader
    Dim returnstring As String
    cmd = New SqlCommand

    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "SP_INS_ORDER"
    cmd.Connection = Connect.Con
    cmd.Parameters.AddWithValue("@UserId", UserID)
    cmd.Parameters.AddWithValue("@OrdWebsite", OrdWebSite)
    cmd.Parameters.AddWithValue("@OrdTrackingId", OrdTrackId)
    cmd.Parameters.AddWithValue("@OrdDeliveryId", OrdDeliveryID)
    cmd.Parameters.AddWithValue("@Eta", OrdEta)
    cmd.Parameters.AddWithValue("@PurchaseDate", PurchaseDate)
    cmd.Parameters.AddWithValue("@NameOnCreditCard", NameOnCreditCard)
    cmd.Parameters.AddWithValue("@Notes", Notes)
    cmd.Parameters.AddWithValue("@CreateUserID", CreateUserId)
    rdr = cmd.ExecuteReader
    dtb = New DataTable
    dtb.Load(rdr)
    Return dtb.Rows(0).Item(0).ToString


    Catch ex As Exception
    Return ex.Message & "Hata olustu, lutfen bilgileri dikkatli girin ya da yardim butonuna tiklayiniz. "

    End Try

    End Function
    Public Shared Function NewCreditCard(ByVal UserId As String, _
    ByVal Number As String, _
    ByVal NameLastName As String, _
    ByVal CardTypeId As String, _
    ByVal CCVCode As String, _
    ByVal ExpirationDate As String, _
    ByVal IsPrimary As Boolean) As String
    Try
    Connect.Connect()

    Dim cmd As SqlCommand
    Dim dtb As DataTable
    dtb = New DataTable
    Dim rdr As SqlDataReader
    Dim returnstring As String


    cmd = New SqlCommand
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Connection = Connect.Con
    cmd.CommandText = "SP_INS_NEW_CREDIT_CARD"
    cmd.Parameters.AddWithValue("@UserId", UserId)
    cmd.Parameters.AddWithValue("@Number", Number)
    cmd.Parameters.AddWithValue("@NameLastName", NameLastName)
    cmd.Parameters.AddWithValue("@CCVNumber", CCVCode)
    cmd.Parameters.AddWithValue("@ExpirationDate", ExpirationDate)
    cmd.Parameters.AddWithValue("@CardTypeId", CardTypeId)
    cmd.Parameters.AddWithValue("@IsPrimary", IsPrimary)

    rdr = cmd.ExecuteReader
    dtb.Load(rdr)
    Connect.Disconnect()
    Return dtb.Rows(0).Item(0).ToString

    Catch ex As Exception
    Return "Error on creating new credit card. " & ex.Message
    End Try

    End Function
    Public Shared Function InsGoldMember(ByVal UserId As String, ByVal RoleId As String) As String
    Try
    Connect.Connect()
    Dim cmd As SqlCommand
    Dim rdr As SqlDataReader
    Dim dtb As DataTable

    cmd = New SqlCommand
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "SP_INS_UPD_GOLD_MEMBER"
    cmd.Connection = Connect.Con
    cmd.Parameters.AddWithValue("@UserId", UserId)
    cmd.Parameters.AddWithValue("@RoleId", RoleId)
    rdr = cmd.ExecuteReader
    dtb = New DataTable
    dtb.Load(rdr)
    Return dtb.Rows(0).Item(0).ToString

    Catch ex As Exception
    Return "Uyelik isleminizde hata olustu. Lutfen yardim menusunde bize ulasin."

    End Try

    Connect.Disconnect()

    End Function
    Public Shared Function InsPayment(ByVal UserId As String,
    ByVal PaymentItem As String,
    ByVal ItemDescription As String, _
    ByVal ItemQuantity As Double, _
    ByVal ItemAmount As Double, _
    ByVal CreateUserId As String,
    ByVal ORDID As Integer) As String
    Try
    Connect.Connect()
    Dim cmd As SqlCommand
    Dim rdr As SqlDataReader
    Dim dtb As DataTable

    cmd = New SqlCommand
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "ezman.SP_CREATE_PAYMENTS"
    cmd.Connection = Connect.Con
    cmd.Parameters.AddWithValue("@PaymentUserId", UserId)
    cmd.Parameters.AddWithValue("@PaymentItem", PaymentItem)
    cmd.Parameters.AddWithValue("@PaymentDesc", ItemDescription)
    cmd.Parameters.AddWithValue("@PaymentAmount", ItemAmount)
    cmd.Parameters.AddWithValue("@ItemQuantity", ItemQuantity)
    cmd.Parameters.AddWithValue("@PaymentCreateUser", CreateUserId)
    cmd.Parameters.AddWithValue("@ORDID", ORDID)
    cmd.ExecuteReader()

    Return FormatCurrency(ItemAmount).ToString & " Payment created."

    Catch ex As Exception
    Return "Payment could not create."

    End Try

    Connect.Disconnect()

    End Function
    Public Shared Function sp_upd_to_paid(ByVal paymentId As String) As String
    Try
    Connect.Connect()
    Dim cmd As SqlCommand
    Dim rdr As SqlDataReader
    Dim dtb As DataTable
    cmd = New SqlCommand
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "SP_UPD_PYM"
    cmd.Connection = Connect.Con
    cmd.Parameters.AddWithValue("@PaymentId", paymentId)
    cmd.ExecuteNonQuery()
    Return "Payment processed."


    Catch ex As Exception
    Return "Payment could not process."

    End Try

    Connect.Disconnect()

    End Function
    Public Shared Function sp_delete_pym(ByVal paymentId As String) As String
    Try
    Connect.Connect()
    Dim cmd As SqlCommand

    cmd = New SqlCommand
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "SP_DEL_PYM"
    cmd.Connection = Connect.Con
    cmd.Parameters.AddWithValue("@PaymentId", paymentId)
    cmd.ExecuteNonQuery()
    Return "Payment processed."


    Catch ex As Exception
    Return "Payment could not process."

    End Try

    Connect.Disconnect()

    End Function

    Public Shared Function SP_INS_STATUS(ByVal ORDERID As Integer, ByVal STATUSID As Integer, ByVal comment As String, ByVal createuser As String)
    Try
    Connect.Connect()
    Dim cmd As SqlCommand
    cmd = New SqlCommand
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "SP_INS_ORDER_STATUS"
    cmd.Connection = Connect.Con
    cmd.Parameters.AddWithValue("@OrdId", ORDERID)
    cmd.Parameters.AddWithValue("@OrdStatusId", STATUSID)
    cmd.Parameters.AddWithValue("@CreateUserId", createuser)
    cmd.Parameters.AddWithValue("@OrdStatusComment", comment)

    cmd.ExecuteNonQuery()
    Return "Status guncellendi. Email gonderildi."


    Catch ex As Exception
    Return "Status guncellenemedi. Email gonderilemedi."

    End Try
    End Function

    Public Shared Sub Delete_User(ByVal userid As String)
    Connect.Connect()

    Dim cmd As SqlCommand
    cmd = New SqlCommand("Delete from aspnet_membership where userid='" & userid & "'", Connect.Con)
    cmd.ExecuteNonQuery()

    End Sub

    End Class

    Monday, February 18, 2013 11:20 PM

Answers

  • User-1618234021 posted

    Where ever you are delcaring returnstring variable, make sure to assing an initial value as empty string, like:

    Dim returnstring As String=""



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 19, 2013 1:40 AM