C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




DROPDOWN LIST CONTROL WITH MS-ACCESS


Posted Date: 27 Mar 2008      Total Responses: 4

Posted By: GOBINATH       Member Level: Silver     Points: 2


HI EVERYBODY........ I HAVE A DROPDOWN LIST IN MY WEBFORM....... NOW I WANT TO GET THE VALUES FROM A TABLE WHICH IS IN MS-ACCESS DATABASE...

I USE VB AS CODE-BEHIND....






Responses

Author: Chaitra R    27 Mar 2008Member Level: GoldRating:     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 2008Member Level: SilverRating:     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 2008Member Level: GoldRating:     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 2008Member Level: GoldRating:     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




Post Reply
You must Sign In to post a response.
Next : Neet to display message without Response.Write() method.
Previous : Dropdownlist...............plz help me ................
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

audio conferencing services

Contact Us    Privacy Policy    Terms Of Use