0

The class should support a function named Profiles which takes a ID as an Integer parameter and returns the name corresponding to that ID as a String. If the name is NULL, then the function should simply return an empty string (String.Empty). If the ID does not exist in the database, the program should throw an ArgumentException (this class is defined in the System namespace).

Public Sub Profiles(ByVal ID As Integer)
        Dim cmd As New SqlCommand("SELECT ID FROM Biodata WHERE ID = @pid", Info)
        Dim da As New SqlDataAdapter(cmd)
        Dim dt As New DataTable

        da.Fill(dt)
        cmd.Parameters.Add("pid", SqlDbType.Int)


        da.Fill(dt)

        If txtName.text = 0 Then
            txtName.text = String.Empty

        End If


        da.Update(dt)

        If Count <> 0 Then RaiseEvent CountChanged(Me, New EventArgs)
        If Average <> 0 Then RaiseEvent AverageChanged(Me, New EventArgs)
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Rogachev
0

i dont know how to extract infor from that database and use in VB.net..

ID is the Primary key in SQL database"Biodata"...when i enter the id number it should get the rest of the Row's values and display..


any idea, tips......???

0

Hi.
May be this code can help you.
Cheers

Dim _table As New DataTable()
Dim _connection As New SqlConnection(mConnectionString)
Dim _commandText As String = "SELECT ID FROM Biodata WHERE ID = @pid"
Dim _adapter As New SqlDataAdapter()
Dim _string As String = String.Empty

With _adapter
.SelectCommand = New SqlCommand(_commandText, _connection)
.SelectCommand.Parameters.Add("@pid", SqlDbType.Int)
.SelectCommand.Parameters(0).Value = id

Try
.Fill(_table)
If _table.Rows.Count = 0 Then
Throw New System.Exception("Null value")
Else
_string = "Yes"
End If
Catch ex As Exception
_string = ex.Message
End Try
End With

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.