![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Convert simple ADODB routine from VBA to VB.net This is so easy in VBA, but every source I research to do it in vb.net seems to have a more difficult and convoluted method involving datasets, tableadapters, etc. etc. What's the easiest way to open a recordset and pull over one record like this with vb.net? Public Function fnGetName(IDS As Integer) As String Dim rs As ADODB.Recordset Dim strSQL As String Dim strName As String 'On Error GoTo procError strSQL = "SELECT * FROM tblPatient WHERE PatientIDS = " & IDS Set rs = New ADODB.Recordset With rs .Open strSQL, CurrentProject.Connection, adOpenForwardOnly If .EOF And .BOF Then ' Else strName = !Lname If Not IsNull(!fname) Then strName = strName & ", " & !fname End If .Close End With fnGetName = strName End Function |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Convert simple ADODB routine from VBA to VB.net Public Function fnGetName(IDS As Integer) As String Using _commmand = New OleDbCommand("SELECT * FROM tblPatient WHERE PatientIDS = ?", CurrentProject.Connection) _commmand.Parameters.AddWithValue("p1", IDS) Using _reader = _com.ExecuteReader() If _reader.HasRows _reader.Read() Dim _fname = _reader.GetOrdinal("fname") Return _reader.GetString(_reader.GetOrdinal("Lname")) & If(_reader.IsDbNull(_fname), String.Empty, ", " & _reader.GetString(_fname)) End If End Using End Using Return Nothing End Function Quote: > Dim rs As ADODB.Recordset > Dim strSQL As String > Dim strName As String > 'On Error GoTo procError > > strSQL = "SELECT * FROM tblPatient WHERE PatientIDS = " & IDS > Set rs = New ADODB.Recordset > With rs > .Open strSQL, CurrentProject.Connection, adOpenForwardOnly > If .EOF And .BOF Then > ' > Else > strName = !Lname > If Not IsNull(!fname) Then strName = strName & ", " & !fname > End If > .Close > End With > fnGetName = strName > End Function news:26kk35d7ubgu6el19gq5v67i6793i8he9k@xxxxxx Quote: > This is so easy in VBA, but every source I research to do it in vb.net > seems to have a more difficult and convoluted method involving > datasets, tableadapters, etc. etc. What's the easiest way to open a > recordset and pull over one record like this with vb.net? > > Public Function fnGetName(IDS As Integer) As String > Dim rs As ADODB.Recordset > Dim strSQL As String > Dim strName As String > 'On Error GoTo procError > > strSQL = "SELECT * FROM tblPatient WHERE PatientIDS = " & IDS > Set rs = New ADODB.Recordset > With rs > .Open strSQL, CurrentProject.Connection, adOpenForwardOnly > If .EOF And .BOF Then > ' > Else > strName = !Lname > If Not IsNull(!fname) Then strName = strName & ", " & !fname > End If > .Close > End With > fnGetName = strName > End Function |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Convert simple ADODB routine from VBA to VB.net Thanks, Stephany. Saved me a lot of time. ....reader.GetOrdinal()... ? Who woulda guessed? ;-) On Fri, 19 Jun 2009 04:54:33 +1200, "Stephany Young" <noone@xxxxxx> wrote: Quote: > > Public Function fnGetName(IDS As Integer) As String > > Using _commmand = New OleDbCommand("SELECT * FROM tblPatient WHERE >PatientIDS = ?", CurrentProject.Connection) > _commmand.Parameters.AddWithValue("p1", IDS) > Using _reader = _com.ExecuteReader() > If _reader.HasRows > _reader.Read() > Dim _fname = _reader.GetOrdinal("fname") > Return _reader.GetString(_reader.GetOrdinal("Lname")) & >If(_reader.IsDbNull(_fname), String.Empty, ", " & _reader.GetString(_fname)) > End If > End Using > End Using > > Return Nothing > > End Function > Quote: >> Dim rs As ADODB.Recordset >> Dim strSQL As String >> Dim strName As String >> 'On Error GoTo procError >> >> strSQL = "SELECT * FROM tblPatient WHERE PatientIDS = " & IDS >> Set rs = New ADODB.Recordset >> With rs >> .Open strSQL, CurrentProject.Connection, adOpenForwardOnly >> If .EOF And .BOF Then >> ' >> Else >> strName = !Lname >> If Not IsNull(!fname) Then strName = strName & ", " & !fname >> End If >> .Close >> End With >> fnGetName = strName >> End Function >"UsenetUser" <spam@xxxxxx> wrote in message >news:26kk35d7ubgu6el19gq5v67i6793i8he9k@xxxxxx Quote: >> This is so easy in VBA, but every source I research to do it in vb.net >> seems to have a more difficult and convoluted method involving >> datasets, tableadapters, etc. etc. What's the easiest way to open a >> recordset and pull over one record like this with vb.net? >> >> Public Function fnGetName(IDS As Integer) As String >> Dim rs As ADODB.Recordset >> Dim strSQL As String >> Dim strName As String >> 'On Error GoTo procError >> >> strSQL = "SELECT * FROM tblPatient WHERE PatientIDS = " & IDS >> Set rs = New ADODB.Recordset >> With rs >> .Open strSQL, CurrentProject.Connection, adOpenForwardOnly >> If .EOF And .BOF Then >> ' >> Else >> strName = !Lname >> If Not IsNull(!fname) Then strName = strName & ", " & !fname >> End If >> .Close >> End With >> fnGetName = strName >> End Function |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Routine Maintenance Advice Wanted | General Discussion | |||
| Calling a JavaScript Sub-Routine | VB Script | |||
| can a property let routine return a value? | VB Script | |||
| re: 'Save As' routine | VB Script | |||
| Generic document manipulation routine | .NET General | |||