Click here to Skip to main content
15,920,606 members
Home / Discussions / Database
   

Database

 
GeneralRe: Abstraction Layer Factory Tool Pin
miah alom19-Aug-05 6:27
miah alom19-Aug-05 6:27 
GeneralRe: Abstraction Layer Factory Tool Pin
airbus38021-Aug-05 2:37
airbus38021-Aug-05 2:37 
GeneralHelp with crystal reports!!!! Pin
korso_rogan17-Aug-05 23:39
korso_rogan17-Aug-05 23:39 
GeneralCannot open backup device Pin
dhtuan17-Aug-05 22:21
dhtuan17-Aug-05 22:21 
Generalusing describe with MS Access Pin
mhmo17-Aug-05 6:57
mhmo17-Aug-05 6:57 
GeneralRe: using describe with MS Access Pin
Rob Graham17-Aug-05 10:20
Rob Graham17-Aug-05 10:20 
GeneralDisconnected Data Question Pin
matthias s.17-Aug-05 6:26
matthias s.17-Aug-05 6:26 
GeneralRe: Disconnected Data Question Pin
ToddHileHoffer17-Aug-05 9:42
ToddHileHoffer17-Aug-05 9:42 
If you are binding the data to a control the sqldatareader is the way to go. You can use the datadapter and a datatable if you don't want a dataset.

Here are two efficient examples. Remember use stored procs. Use the dispose method when possible. Use connection.dispose instead of connection.close. DataAdapters check for an open connection anyway so there is no need to open it.

<br />
Public Function GetDataTable(ByVal strConnectionString As String, ByVal strProcName As String) As DataTable<br />
        Dim Conn As New SqlConnection<br />
        Conn.ConnectionString = strConnectionString<br />
<br />
        Dim Cmd As New SqlCommand<br />
        Cmd.Connection = Conn<br />
        Cmd.CommandType = CommandType.StoredProcedure<br />
        Cmd.CommandText = strProcName<br />
        Dim DA As New SqlDataAdapter<br />
        DA.SelectCommand = Cmd<br />
        Dim DT As New DataTable<br />
        DA.Fill(DT)<br />
        DA.Dispose()<br />
        Cmd.Dispose()<br />
        Return DT<br />
<br />
<br />
    End Function<br />
<br />
<br />
Public Function FillDropDownList(ByRef DDL As DropDownList, ByVal strConnectionString As String, ByVal strProcName As String) As Boolean<br />
        DDL.Items.Clear()<br />
        Dim Conn As New SqlConnection<br />
        Conn.ConnectionString = strConnectionString<br />
<br />
        Dim Cmd As New SqlCommand<br />
        Cmd.Connection = Conn<br />
        Cmd.CommandType = CommandType.StoredProcedure<br />
        Cmd.CommandText = strProcName<br />
        Dim DR As SqlDataReader<br />
        Conn.Open()<br />
        DR = Cmd.ExecuteReader<br />
        DDL.DataSource = DR<br />
        DDL.DataValueField = DR.GetName(0)<br />
        If DR.FieldCount > 1 Then<br />
            DDL.DataTextField = DR.GetName(1)<br />
        Else<br />
            DDL.DataTextField = DR.GetName(0)<br />
        End If<br />
<br />
        DDL.DataBind()<br />
        DR.Close()<br />
        Conn.Dispose()<br />
        Cmd.Dispose()<br />
        DDL.Items.Insert(0, "")<br />
<br />
<br />
    End Function<br />




"People who never make mistakes, never do anything."

My blog
http://toddsnotsoamazinglife.blogspot.com/
GeneralRe: Disconnected Data Question Pin
miah alom19-Aug-05 6:30
miah alom19-Aug-05 6:30 
QuestionSQL 2000 - IF / THEN bug? Pin
Anthony Ford17-Aug-05 5:11
Anthony Ford17-Aug-05 5:11 
AnswerRe: SQL 2000 - IF / THEN bug? Pin
ToddHileHoffer17-Aug-05 9:46
ToddHileHoffer17-Aug-05 9:46 
GeneralRe: SQL 2000 - IF / THEN bug? Pin
Anthony Ford17-Aug-05 10:02
Anthony Ford17-Aug-05 10:02 
GeneralRe: SQL 2000 - IF / THEN bug? Pin
ToddHileHoffer17-Aug-05 10:42
ToddHileHoffer17-Aug-05 10:42 
GeneralSql server Pin
chandru_inbox17-Aug-05 0:29
chandru_inbox17-Aug-05 0:29 
GeneralRe: Sql server Pin
Yulianto.18-Aug-05 16:44
Yulianto.18-Aug-05 16:44 
GeneralRe: Sql server Pin
miah alom19-Aug-05 6:34
miah alom19-Aug-05 6:34 
GeneralNeed advice on numerical data types for numbers like ##,###.## Pin
FTrader16-Aug-05 20:41
FTrader16-Aug-05 20:41 
GeneralRe: Need advice on numerical data types for numbers like ##,###.## Pin
Colin Angus Mackay16-Aug-05 22:28
Colin Angus Mackay16-Aug-05 22:28 
GeneralRe: Need advice on numerical data types for numbers like ##,###.## Pin
FTrader16-Aug-05 23:16
FTrader16-Aug-05 23:16 
GeneralRe: Need advice on numerical data types for numbers like ##,###.## Pin
Dan Neely17-Aug-05 10:38
Dan Neely17-Aug-05 10:38 
GeneralRe: Need advice on numerical data types for numbers like ##,###.## Pin
FTrader17-Aug-05 12:44
FTrader17-Aug-05 12:44 
GeneralRe: Need advice on numerical data types for numbers like ##,###.## Pin
Dan Neely18-Aug-05 7:57
Dan Neely18-Aug-05 7:57 
GeneralSome info about .NET decimal Pin
FTrader17-Aug-05 1:57
FTrader17-Aug-05 1:57 
QuestionDeleted entries reappearing in Access 2000 DB? Pin
mav.northwind16-Aug-05 20:28
mav.northwind16-Aug-05 20:28 
Questionhow to accessing Paradox use ADO Pin
ebinaini16-Aug-05 19:20
ebinaini16-Aug-05 19:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.