| Author: Chaitra R 27 Mar 2008 | Member Level: Gold | Rating: Points: 2 |
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) ' Put user code to initialize the page here Dim connectionString As String = "server=YourServer; uid=sa;" + "pwd=YourPassword; database=cust" Dim commandString As String = "Select name from cust" ' create the data set command object ' and the DataSet Dim dataAdapter As New SqlDataAdapter(commandString, connectionString) Dim dataSet As New DataSet() ' fill the data set object dataAdapter.Fill(dataSet, "cust") ' Get the table from the DataSet Dim dataTable As DataTable = dataSet.Tables(0) ListBox1.DataSource = dataTable.DefaultView ListBox1.DataTextField = "name" ListBox1.DataBind() End Sub
|
| Author: vijayavasavi narapuram 27 Mar 2008 | Member Level: Silver | Rating: Points: 2 |
imports system.data imports system.data.sqlclient
write this code in page_load event
dim sqlconnection as new sqlconnection("provider=microsoft.jet.oledb4.0;database=......(your database complete path);datasource=......(your server name)") dim da as new sqldataadapter("Select * from your tablename",cn) dim ds as new dataset da.fill(ds,"yourtablename) dropdownlist1.datasource=ds.tables[0] dropdownlist1.databind()
Hope it is useful to u.....
|
| Author: victoria 27 Mar 2008 | Member Level: Gold | Rating: Points: 2 |
Dim s As String s = ConfigurationManager.ConnectionStrings("Constr").ConnectionString Dim q As String = "select *from mytb" Dim con As OleDbConnection = New OleDbConnection(s) Dim cmd As OleDbCommand = New OleDbCommand(q, con) con.Open() Dim adp As OleDbDataAdapter = New OleDbDataAdapter(q, con) adp.SelectCommand = cmd Dim ds As DataSet = New DataSet() adp.Fill(ds, "mytb") Dim count As Integer count = ds.Tables("mytb").Rows.Count Dim i As Integer If Not IsPostBack Then For i = 0 To count - 1 DropDownList1.Items.Add(ds.Tables("mytb").Rows(i)("number").ToString()) Next End If
i am putting the connection string in web.config file like this.
<connectionStrings> <add name="ConStr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\mydb.mdb" providerName="System.Data.OleDb"/> </connectionStrings>
|
| Author: SK GUPTA 28 Mar 2008 | Member Level: Gold | Rating: Points: 2 |
You Try this code. I have used it in many aplications.
Imports System.Data.OleDb Public Class hostel Dim cn As New OleDbConnection() Dim cmd As New OleDbCommand() Dim dr As OleDbDataReader Private Sub hostel_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.Items.Clear() cn = New OleDbConnection("provider=Microsoft.jet.oledb.4.0; Data source=D:\HOSTEL2.mdb") cn.Open() Try cmd = New OleDbCommand("select Name from BOYS", cn) dr = cmd.ExecuteReader While dr.Read ComboBox2.Items.Add(Trim(dr("Name"))) End While Catch ex As Exception MsgBox(ex.Message) cn.Close() End Try End Sub
|