locked
(Sumber: milist MUGI) koneksi VB.NET RRS feed

  • Pertanyaan

  • Dear All mau nanya contoh script yang biasa dipakai untuk mengkoneksikan ke database di VB.NET gmn ya?

    thanxs

     



    Robby


    Rabu, 08 Juni 2011 07.05
    Moderator

Jawaban

  • gampang om :)
    contoh pakai sql server, display ke datagridview

    dim LocalStr As String = "Data Source=[namakomputer];Initial Catalog=[namadatabase];Persist Security Info=True;User ID=[username db];Password=[password db user];Connect Timeout=45

            Using cn As New SqlClient.SqlConnection
                cn.ConnectionString = LocalStr
                cn.Open()
                Using cmd As New SqlClient.SqlCommand
                    dim da as new sqlclient.sqldataadapter
                    dim dt as datatable
                    cmd.Connection = cn
                    SQL = "select bla bla from bla bla where bla bla"
                    cmd.CommandText = SQL
                    da.selectcommand = cmd
                    da.fill(dt)
                    datagridview1.datasource = dt               
                End Using
            End Using

    Dijawab oleh: Luki Ishwara

    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Rabu, 08 Juni 2011 07.06
    Moderator

Semua Balasan

  • Silahkan di cek disini : http://connectionstrings.com/

     

    --

    Regards,

     

    Rully Yulian MF


    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Disarankan sebagai Jawaban oleh Rengga Dinata Rabu, 12 Februari 2014 08.45
    Rabu, 08 Juni 2011 07.06
    Moderator
  • gampang om :)
    contoh pakai sql server, display ke datagridview

    dim LocalStr As String = "Data Source=[namakomputer];Initial Catalog=[namadatabase];Persist Security Info=True;User ID=[username db];Password=[password db user];Connect Timeout=45

            Using cn As New SqlClient.SqlConnection
                cn.ConnectionString = LocalStr
                cn.Open()
                Using cmd As New SqlClient.SqlCommand
                    dim da as new sqlclient.sqldataadapter
                    dim dt as datatable
                    cmd.Connection = cn
                    SQL = "select bla bla from bla bla where bla bla"
                    cmd.CommandText = SQL
                    da.selectcommand = cmd
                    da.fill(dt)
                    datagridview1.datasource = dt               
                End Using
            End Using

    Dijawab oleh: Luki Ishwara

    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Rabu, 08 Juni 2011 07.06
    Moderator