I wana know how can i use a value from a sql table that i added from another form?
It basically supposed to validate that whatever was the last recorded added in the other form(eg formA) , i must then use those same values from the sql , into another form(eg formB).If i type a value in the textbox( in formB), it basically must validate that, the value i typed in, is not the record that was enterd in the other form(formA) (the last record added in that form)

Here is my coding that i did:

    Dim conmid As New SqlClient.SqlConnection("Data Source=CHETS-TOSHIBA\SQLEXPRESS;Initial Catalog=PlanetDiscLibrary;Integrated Security=True")
    Dim sqlsmid As String = "SELECT TOP 1 '" + txtMID.Text + "' from request ORDER BY request_id DESC"
    Dim cmdmid As New SqlClient.SqlDataAdapter(sqlsmid, conmid)
    Dim dsmid As New DataSet
    Dim memid As Integer
    Dim dtmeid As DataTable
    cmdmid.Fill(dsmid, "member")
    dtmeid = dsmid.Tables("member")
    memid = dtmeid.Rows.Count
    If memid = 0 Then
        MessageBox.Show("Not request Member ID", "MemberIDError", MessageBoxButtons.OK, MessageBoxIcon.Error)
        txtMID.Text = ""
        Return False
    End If

How else can i do this please hekp. Thanks

You can try using ident_current. It will return the last identity value generated. For example, SELECT IDENT_CURRENT('dbo.request')

If each record has a primary key that is an auto-incrementing (identity) value then you could compare the field against the field returned by the record with key= MAX(pkID) where pkID is whatever name you are using for your primary key.

Thanks but i wana use two values from the other form

These values will be entered into a textbox.

so how do i relate each textbox to that particular value from the other forms value?
eg:
textbox1 value = member_id(M001)
textbox2 value = album_id(A001)

form1 details are in a table called request coloumn names are: member_id(M001), album_id(A001), and request_id(R001 is used as primary key)

Form2 uses member_id and album_id values in the textboxs to be stored into transaction table.

Can I ask what each form is supposed to do? Especially interested in the second form.
Anyway, depending on the way you call the second form it might be easier to just pass these 2 values in the second form as parameters.

ITG-JM and Reverend Jim are right to also point you to get a unique field. If you get that value then you can query your db for any info you like - or have your db compare the record with that ID with the info you are trying to pass.

The first form is the request form. This form is used to make the request of what the client orders. e.g member_id(M001) makes a request on a dvd or cd (A001) then i save the details in server under the table request.

The second form is the transaction form. Here this form is taking the member_id and the album_id from the request form and all the transaction form has to do is put dates as when it was issued and when it must be returned. the dates must be 5 days apart as i have to calulate when the cusomer has to return the album(But that calculating part is nothing to do with this form)

i have uploaded some pictures so you can see what it is about.

Thanks guys for all the help

Attachments add_transaction.png 312.85 KB Request_form.png 323.14 KB

So Reverend Jim.How do i go about using that method that you have mentioned in my coding eariler?

Please relate to my code and give me an example.
Thanks

select * from Test1 where pkID = (select MAX(pkID) from Test1)

This will select the record with the largest pkID. This is froma table named "Test1" and a primary key named "pkID" which is int and Identity.

Okay the coding you got there works , but how do i use it to capture the value and confirm its the right, and that it was the last request made as im using it to pick (member_id and album_id) in my memberid textbox and albumid textbox(in the transaction form)?

I don't understand what you mean by "capture the value". You retrieve the most recent record from the database using the query then compare the fields in the result to the data entered by the user on your form. If they match then the user-entered data is invalid. "capture the value" can mean several different things. Can you please clarify?

This article has been dead for over six months. Start a new discussion instead.