Results 1 to 3 of 3

Thread: VB.NET Show an Problem...

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    1

    Unhappy VB.NET Show an Problem...

    I cannot read select i want to method: for example....
    I am chose dropdownlist in records, but When click PlaceOrder button, label will display when i chose records....but why display first records???cannot display second or......etc records ???can us tell me, thanks!


    this is a WebForm1.aspx.vb :
    =============================================
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim myConnection As SqlConnection
    Dim myCommand As SqlCommand
    Dim myReader As SqlDataReader
    Dim sql As String
    Dim ConnStr As String

    sql = "Select * From Shippers"
    ConnStr = "Server=localhost;uid=sa;pwd=frances;database=Northwind"

    myConnection = New SqlConnection(ConnStr)
    myConnection.Open()
    myCommand = New SqlCommand(sql, myConnection)
    myReader = myCommand.ExecuteReader()
    ShipMethod.DataSource = myReader
    ShipMethod.DataBind()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    YouSelected.Text = "You Order will be Delivered vis : " & _
    ShipMethod.SelectedItem.Text

    End Sub
    =============================================

    this is a WebForm1.aspx :

    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="test.WebForm1"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:label id="Label1" style="Z-INDEX: 101; LEFT: 160px; POSITION: absolute; TOP: 104px" runat="server"
    Font-Bold="True">Please Select your delivery method:</asp:label><asp:button id="Button1" style="Z-INDEX: 103; LEFT: 176px; POSITION: absolute; TOP: 144px" runat="server"
    Text="Place Order"></asp:button><asp:dropdownlist id="ShipMethod" style="Z-INDEX: 102; LEFT: 416px; POSITION: absolute; TOP: 104px"
    DataTextField="CompanyName" DataValueField ="ShipperID" runat="server"></asp:dropdownlist>
    <asp:Label id="YouSelected" style="Z-INDEX: 104; LEFT: 160px; POSITION: absolute; TOP: 192px"
    runat="server" Width="320px" Height="40px"></asp:Label></form>
    </body>
    </HTML>

  2. #2
    Lively Member
    Join Date
    Aug 2003
    Location
    When?!?!
    Posts
    108
    Your posting in the wrong forms buddy
    DannyJoumaa
    Advanced VB6 Programmer
    Intermediate-Advanced VB .NET Programmer
    Intermediate C# Programmer
    Intermediate Win32 Developer
    Beginner Mac OS X Developer
    Contact: [email protected]

    Favorite Sayings:
    "Every time you open your mouth, you prove your an idiot."
    "God is a programmer. Satan is a bug. Life is debugging."

  3. #3
    Junior Member JohannS's Avatar
    Join Date
    Aug 2001
    Location
    Pretoria, South Africa
    Posts
    21
    *****, you need to work on that English there:

    Anyway, here's what I'd do if I were you.

    Create variables somewhere for the ConnectionString, and SelectString.

    In the Page Load Sub, put this:

    Dim myConnection As New SqlClient.SqlConnection(Connectionstring)
    Dim myCommand As New SqlClient.SqlCommand(strSelect, myConnection)
    Dim da As New SqlClient.SqlDataAdapter()
    Dim ds As New DataSet()
    da.SelectCommand = myCommand
    myConnection.Open()
    da.Fill(ds)
    myConnection.Close()
    myConnection.Dispose()


    Now you have a dataset with the Data you need.

    To populate the DropDownList, do this:

    dropdownlist1.datasource = ds
    dropdownlist1.DataTextField = "Put the Field that holds the Data in Here"
    dropdownlist1.databind


    Then, in the button event, do this:

    label1.text = dropdownlist1.selecteditem.text


    That, should do it.

    Cheers
    It was an electrical problem sir, a conrod went through the block, and knocked the distributer off.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width