| | |
How to get infor from SQL database in vb
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 7
Reputation:
Solved Threads: 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).
VB.NET Syntax (Toggle Plain Text)
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)
Last edited by Panithuli; Nov 29th, 2008 at 2:28 pm.
•
•
Join Date: Nov 2008
Posts: 16
Reputation:
Solved Threads: 2
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
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
![]() |
Similar Threads
- An OpenSource Database (C++)
Other Threads in the VB.NET Forum
- Previous Thread: Different .NET Window Forms??
- Next Thread: Datatable and datarow.
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application arithmetic array assignment basic binary box button buttons center click code combo combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall login math memory mobile module ms msaccess mssqlbackend mysql navigate net opacity pan peertopeervideostreaming picturebox picturebox1 port print printpreview problemwithinstallation project record regex reports" reuse right-to-left save savedialog search serial sorting sqldatbase storedprocedure string temp textbox timer txttoxmlconverter updown useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml





