2 Replies - 333 Views - Last Post: 13 July 2014 - 07:36 PM Rate Topic: -----

#1 ChokeOnThis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 02-June 14

Trying to connect a Doubly Linked Database using SQL and VB.net

Posted 30 June 2014 - 03:44 AM

Have to create a database using a sql script which provides me with database tables in the sql server. It provides samples and the relationships.

- I need to prompt the user to input an Account Number which is 8 digits long. It needs to open the sql database to check the acc number.

- Need to use an appropriate class to store the transaction records.

- Create a doubly linked list using the LinkedList(of T) generic to load it with transaction details from the sql Transactions table with the appropriate account number.

- Display the transactions to the user.

So, what I have so far to me seems right, what I'm having problems with is. I am getting a SQL Exception(A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified))

If anyone could provide me with some information, that would be much appriciated.

Public Class Accounts

    Public Sub LoadData()
        Dim value As Integer
        value = InputBox("Enter your 8 Digit Account Number", "Account Number", 0) 'InputBox for Account Number
        Dim account As New LinkedList(Of Transactions)() ' doubly linked list
        Dim conn As New SqlConnection("Data Source=(Server)\sqlexpress; Initial Catalog=Library; Integrated Security=True")'sql connection object. Is that how it should be?
        Dim cmd As New SqlCommand("Select * From [Transactions] Where AccountNo = " & value, conn)'Search sql database for account number
        conn.Open()
        Dim reader As SqlDataReader = cmd.ExecuteReader
        While (reader.Read())
            Dim theAccount As New Transactions(reader.GetInt32(0), reader.GetDateTime(1), reader.GetString(2), reader.GetString(3), reader.GetInt32(4))
            account.AddFirst(theAccount)
            lbOutput.Items.Add(theAccount)
        End While
        reader.Close()
        conn.Close()

    End Sub

    Private Sub btnExecute_Click(sender As System.Object, e As System.EventArgs) Handles btnExecute.Click
        LoadData()
    End Sub
End Class

Public Class Transactions
    'Variables of the Transaction Table Created
    Dim AccountNo As Integer
    Dim tDate As Date
    Dim Description As String
    Dim DebCard As String
    Dim Amount As Integer

    Public Sub New(ByVal AccNo As Integer, ByVal Tdate As Date, ByVal Descrip As String, ByVal Card As String, ByVal amount As Integer) 'constructor
        Me.AccountNo = AccNo
        Me.tDate = Tdate
        Me.Description = Descrip
        Me.DebCard = Card
        Me.Amount = amount
    End Sub

End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Trying to connect a Doubly Linked Database using SQL and VB.net

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,473
  • Joined: 12-June 08

Re: Trying to connect a Doubly Linked Database using SQL and VB.net

Posted 30 June 2014 - 08:19 AM

07	        Dim conn As New SqlConnection("Data Source=(Server)\sqlexpress; Initial Catalog=Library; Integrated Security=True")'sql connection object. Is that how it should be?



Have you consulted http://www.connectionstrings.com ?
Was This Post Helpful? 0
  • +
  • -

#3 ChokeOnThis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 02-June 14

Re: Trying to connect a Doubly Linked Database using SQL and VB.net

Posted 13 July 2014 - 07:36 PM

Thanks for that, but it was a compile problem that I sorted. I need to get the output of this to read from the doubly linked list, not sure how to do that. I have a list box called lbOutput to output the list, I got told I wasn't allowed to just use the reader to output the data, have to get the data from the doubly linked list and output it from there, would I use a listbox or should I use a textbox or something else?

Dim value As Integer = InputBox("Enter your 8 Digit Account Number", "Account Number", 0) 'Prompt user for Account Number 
        Dim account As New LinkedList(Of Transactions)() ' doubly linked list
        Dim conn As New SqlConnection("Data Source=;Initial Catalog=;Integrated Security=True")  'sql connection object
        Dim cmd As New SqlCommand("Select * From Transactions Where AccountNo = '" & value & "'", conn) 'sql connection to Transaction table

        conn.Open()

        Dim reader As SqlDataReader = cmd.ExecuteReader 'Read from sql server
        While (reader.Read()) 'Read the user input number
            
            Dim theAccount As New Transactions(reader.GetInt32(0), reader.GetDateTime(1), reader.GetString(2), reader.GetString(3), reader.GetDouble(4)) 'New Transaction node
            account.AddFirst(theAccount) 'Add it to the doubly linked list

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1