How to get infor from SQL database in vb

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 7
Reputation: Panithuli is an unknown quantity at this point 
Solved Threads: 0
Panithuli Panithuli is offline Offline
Newbie Poster

How to get infor from SQL database in vb

 
0
  #1
Nov 29th, 2008
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).


  1. Public Sub Profiles(ByVal ID As Integer)
  2. Dim cmd As New SqlCommand("SELECT ID FROM Biodata WHERE ID = @pid", Info)
  3. Dim da As New SqlDataAdapter(cmd)
  4. Dim dt As New DataTable
  5.  
  6. da.Fill(dt)
  7. cmd.Parameters.Add("pid", SqlDbType.Int)
  8.  
  9.  
  10. da.Fill(dt)
  11.  
  12. If txtName.text = 0 Then
  13. txtName.text = String.Empty
  14.  
  15. End If
  16.  
  17.  
  18. da.Update(dt)
  19.  
  20. If Count <> 0 Then RaiseEvent CountChanged(Me, New EventArgs)
  21. If Average <> 0 Then RaiseEvent AverageChanged(Me, New EventArgs)
Last edited by Panithuli; Nov 29th, 2008 at 2:28 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 7
Reputation: Panithuli is an unknown quantity at this point 
Solved Threads: 0
Panithuli Panithuli is offline Offline
Newbie Poster

Re: How to get infor from SQL database in vb

 
0
  #2
Nov 29th, 2008
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......???
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 16
Reputation: Rogachev is an unknown quantity at this point 
Solved Threads: 2
Rogachev Rogachev is offline Offline
Newbie Poster

Re: How to get infor from SQL database in vb

 
0
  #3
Nov 29th, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC