Hi, I have a project that I’ve been trying to do for months and months on my own, but it has got to the point where I can’t carry on because I’m so stuck, and all the tuts I try to follow don’t work for what I need.

I am trying to create a program that keeps account of clothing that is lent to a certain person in the cadet force. So for example….

User walks in and asks for a combat jacket > *program loads up onto a form that holds a datagrid view and displays all the members. The assistant selects the users account from the datagrid viewer and clicks a button saying ‘select’. The program then loads the information that is held in a table called tblClothing into labels and textboxs etc saying what they have. I.e: Combat Jacket is loaded into a label, ‘2’ is loaded into a numerical box to say they have 2 combat jackets issued, and a check box is checked to say the item has been issued but not returned.* > we find a correct combat jacket and give it to the user who then goes. > *back in the program the numerical box is updated to ‘3’ by the assistant so we now know that 3 combat jackets have been issued to that user and if we do not have 3 returned then we can charge them for the loss. The assistant then clicks the ‘save button’ and the updated information is saved back into the database.*

I know that all seems very complicated but when you actually think about it not much actually happens. Below is a picture of what I imagine the database structure and relationships to look like but could you please tell me any recommendations you have for me to change it.

http://i223.photobucket.com/albums/dd28/echocpt/tbls.jpg

Ok so presuming the database is good, the next help I need is linking that database into the form. I understand how to get it to show in the datagrid view but I do not know how to select a row and load it’s separate cells into textboxs etc….

Thanks for any help, it’s all appreciated….please try to help

I have also attached my soloution so if you want to d/l and see what i imagine for myself please do. It should help you understand better. Thanks

I have used this code when a row in the datagrid is doubleclicked.

Private Sub dgvOrders_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
        
        orderid = Me.dgvOrders.SelectedCells(0).Value 
        Dim myconnection As New SqlConnection(myconn)
        
        Dim sstring As String = "SELECT * From Orders Where OrderId = " & orderid & ""
        Dim mycomm As New SqlCommand(sstring, myconnection)
        myconnection.Open()
        Dim myReader As SqlDataReader = mycomm.ExecuteReader()

            While (myReader.Read())
            price = (myReader.GetDecimal(0))
            Me.txtCCNum.Text = (myReader.GetString(1))
            Me.txtCCExp.Text = (myReader.GetString(2))
            Me.txtName.Text = (myReader.GetString(3))
            Me.txtCCSec.Text = (myReader.GetString(4))
            Me.txtAddy.Text = (myReader.GetString(5))
            Me.txtCCType.Text = (myReader.GetString(6))
        End While
        myReader.Close()
        
    End Sub

Hope this helps.

I have used this code when a row in the datagrid is doubleclicked.

Private Sub dgvOrders_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
        
        orderid = Me.dgvOrders.SelectedCells(0).Value 
        Dim myconnection As New SqlConnection(myconn)
        
        Dim sstring As String = "SELECT * From Orders Where OrderId = " & orderid & ""
        Dim mycomm As New SqlCommand(sstring, myconnection)
        myconnection.Open()
        Dim myReader As SqlDataReader = mycomm.ExecuteReader()

            While (myReader.Read())
            price = (myReader.GetDecimal(0))
            Me.txtCCNum.Text = (myReader.GetString(1))
            Me.txtCCExp.Text = (myReader.GetString(2))
            Me.txtName.Text = (myReader.GetString(3))
            Me.txtCCSec.Text = (myReader.GetString(4))
            Me.txtAddy.Text = (myReader.GetString(5))
            Me.txtCCType.Text = (myReader.GetString(6))
        End While
        myReader.Close()
        
    End Sub

Hope this helps.

Thanks a lot for replying, however i am now a lil confused, 1stly my database is a mdb not SQL but that dosnt matter cause i changed that all. So i took your code and had a lil play around to try and get it to work but all i found was i got this error when i tried to run it.

Format of the initialization string does not conform to specification starting at index 0.

I think maybe this has something to do with my database structue? I'm realy not sure tho. If you want to see the database I am using its attached to this reply.

The code I put into my program was this, but there were some bits I'm ashamed to say i did'nt quite understand. I highlighted them in red

Private Sub btnUserSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUserSelect.Click
        Dim orderid As String
        Dim price As String
        orderid = Me.dgvMembers.SelectedCells(0).Value
        Dim myconnection As New OleDb.OleDbConnection("C:\Documents and Settings\Alex\My Documents\Database2.mdb")

        Dim sstring As String = "SELECT * From Orders Where OrderId = " & orderid & ""
        Dim mycomm As New OleDb.OleDbCommand(sstring, myconnection)
        myconnection.Open()
        Dim myReader As OleDb.OleDbDataReader = mycomm.ExecuteReader()

        While (myReader.Read())
            price = (myReader.GetDecimal(0))
            Me.txtUser.Text = (myReader.GetString(1))
            Me.txtFirst.Text = (myReader.GetString(2))
            Me.txtLast.Text = (myReader.GetString(3))
            Me.txtYear.Text = (myReader.GetString(4))
            Me.txtSection.Text = (myReader.GetString(5))
        End While
        myReader.Close()
    End Sub

Thanks for the help so far much appretiated, hope to hear from you soon.

ok forget that last post......i'v played around more with the code and this is what i have it looking like....

Private Sub btnUserSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUserSelect.Click
      
	Dim username As String
        USERNAME = Me.dgvMembers.SelectedCells(0).Value

        Dim con As OleDb.OleDbConnection
        Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand()

        Dim sConStr As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data " _
            & "Source=C:\Documents and Settings\Alex\My Documents\Database2.mdb"

        con = New OleDb.OleDbConnection(sConStr)

        cmd.Connection = con
        cmd.CommandText = "SELECT * From TBLCADETS Where USERNAME = " & username & ""

        con.Open()
        Dim myReader As OleDb.OleDbDataReader = cmd.ExecuteReader()

        While (myReader.Read())
            Me.txtUser.Text = (myReader.GetString(1))
            Me.txtFirst.Text = (myReader.GetString(2))
            Me.txtLast.Text = (myReader.GetString(3))
            Me.txtYear.Text = (myReader.GetString(4))
            Me.txtSection.Text = (myReader.GetString(5))
        End While
        myReader.Close()
        con.Close()

    End Sub

However could someone please tell me why this error is coming up on the line in red in the code above

No value given for one or more required parameter.

Thanks for anyhelp

when you debug are you making sure that the username is actually being set? test this first. sounds like something is empty.

kk, i will do. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.