|
-
Sep 1st, 2005, 11:03 AM
#1
Thread Starter
Fanatic Member
populating of a ddl
want to populate a drop down list
my code doesnt seem to work, is it the fill method is a problem??
in my table i have just 2 columns with only one column name
table name = tb_area
columns = area_code, area_name
i just want to display area name.
Private ddlArea As New DropDownList
Private daArea As New SqlDataAdapter
.................
daArea.SelectCommand = New SqlCommand("SELECT * from tb_area", oSQLConn)
ddl_area.Fill(ddlArea)
ddlArea.DataSource = daArea.Tables(0)
ddlArea.DataBind()
oSQLConn.Close()
-
Sep 1st, 2005, 12:57 PM
#2
Hyperactive Member
Re: populating of a ddl
Try:
Code:
OleDbCommand myCmd = new OleDbCommand("SELECT * from tb_area", oSQLConn)
OleDbDataReader myReader;
oSQLConn.Open();
myReader = myCmd.ExecuteReader();
DDL.DataSource = myReader;
DDL.DataTextField = "area_name";
DDL.DataValueField = "area_name";
DDL.DataBind();
myReader.Close();
oSQLConn.Close();
-
Sep 2nd, 2005, 03:41 AM
#3
Thread Starter
Fanatic Member
Re: populating of a ddl
mine is in sql and i dont have a data reader declared , when i try to declare one i get the dreaded squiggle lines.
Code:
Private Sub fill_area()
Dim sqlfillarea As New SqlCommand("SELECT * from tb_area", oSQLConn)
'daArea.Fill()
oSQLConn.Open()
Me.ddlArea.DataSource = daArea
Me.ddlArea.DataValueField = "area_name"
Me.ddlArea.DataTextField = "area_name"
Me.ddlArea.DataBind()
oSQLConn.Close()
Last edited by d2005; Sep 2nd, 2005 at 04:15 AM.
-
Sep 5th, 2005, 09:39 AM
#4
Hyperactive Member
Re: populating of a ddl
How are you declaring your SqlDataReader object, can i see the code?
-
Sep 5th, 2005, 11:41 AM
#5
Thread Starter
Fanatic Member
Re: populating of a ddl
dont think i have a datareader, heres the whole heap,
any help would be much appreciated
VB Code:
Imports System
Imports System.data
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
' declare the data set and data adapters
Private ddlArea As New DropDownList
Private daArea As New SqlDataAdapter
Dim cmdselect As SqlCommand
Dim area_reader As SqlDataReader
'declare connection variable to database
Dim oSQLConn As SqlConnection = New SqlConnection
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'on page load connect to databse
user_reg()
' fill_area()
End Sub
Private Sub user_reg()
' connect to the databse
oSQLConn.ConnectionString = "Data Source=(local);" & _
"Initial Catalog=TaT;" & _
"Integrated Security=SSPI"
oSQLConn.Open()
oSQLConn.Close()
End Sub
Private Sub fill_area()
Dim sqlfillarea As New SqlCommand("SELECT * from tb_area", oSQLConn)
'ddlArea.fill(ddlArea)
oSQLConn.Open()
Me.ddlArea.DataSource = daArea
Me.ddlArea.DataValueField = "area_name"
Me.ddlArea.DataTextField = "area_name"
Me.ddlArea.DataBind()
oSQLConn.Close()
End Sub
Private Sub btn_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_submit.Click
Dim regtime As New DateTime
'use textboxes as entries
' ,c_user_postcode,c_user_tel_alt,c_user_country, ' now() ','uk'
Dim sqlInsertuser As New SqlCommand("INSERT INTO tb_user(c_user_id,c_user_fname,c_user_sname,c_username_login,c_user_password,c_user_house,c_user_street,c_user_town,c_user_country,c_user_postcode,c_user_email,c_user_tel_alt,c_county,c_date_registered) VALUES('" & txt_mobile.Text & "','" & txt_fname.Text & "','" & txt_sname.Text & "','" & txt_username.Text & "','" & txt_password.Text & "','" & txt_house.Text & "','" & txt_street.Text & "','" & txt_town.Text & "','uk','" & txt_post.Text & "','" & txt_email.Text & "','" & txt_tel.Text & "','" & txt_county.Text & "',getDate());", oSQLConn)
sqlInsertuser.Connection.Open()
sqlInsertuser.ExecuteNonQuery()
oSQLConn.Close()
End Sub
the inserts are working ok but the ddl is not doin nothin, this is a test page for learning purposes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|