Results 1 to 4 of 4

Thread: make a table open up on form load

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    make a table open up on form load

    Hi guys,


    I have a form1 that checks the log in username with the password. That works fine.

    Now the username Items are in a dropdownlist and represent tables. Now I need to open on form 2 that particular table that has been selected in form1.

    (DropDownList1.SelectedItem.Value ) is the name of the table to be called .

    Eg if the item selected on the dropdownlist was Table1 and that was validated with the password then on Form2 , Table2 will open up in a DataGrid.

    Can someone give me some help cos its my first ADO.NEt project . Thanks loads
    Last edited by angelica; Dec 29th, 2004 at 04:09 AM.

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: make a table open up on form load

    Hi
    A little sample code , you need to modify your connection string and sql query. Add a sqlconnection, a SqlDataAdapter1 and and datagrid on a form
    Code:
    Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    dim contring as string = "data source=YourServer;initial catalog=YourDataBase;persist security info=False;user id=YourUser;password=YourUserPassaword;workstation id=" & System.Environment.MachineName & ";packet size=32767;application name=YourAppName"
    dim ds as new dataset
            Me.SqlConnection1.ConnectionString = constring
            Me.SqlConnection1.Open()
            Me.SqlDataAdapter1.SelectCommand.Connection = Me.SqlConnection1
            Me.SqlDataAdapter1.SelectCommand.CommandType = CommandType.Text
            Me.SqlDataAdapter1.SelectCommand.CommandText = "select * from YourTable order by YourField1 desc"
            Me.SqlDataAdapter1.Fill(ds, "YourTable")
    
            Me.DataGrid1.DataSource = ds.Tables("YourTable")
            Me.DataGrid1.ReadOnly = True
            Me.SqlConnection1.close
    end sub
    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: make a table open up on form load

    hi Asgorath,


    Will try it out, and come back if I m stuck cos I dont have much experience as yet. Thanks loads for your help!

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: make a table open up on form load

    Hi Asogarth & Guys,

    Can you check out some syntax mistakes pls cos I dont fully understood what I should do. I tried to insert my fields and table but its a mess I guess. Anyways I have loads to errors dealing with not declared. Can u help me out pls


    Code:
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
        Protected WithEvents Button3 As System.Web.UI.WebControls.Button
        Protected WithEvents Button2 As System.Web.UI.WebControls.Button
        Protected WithEvents Button1 As System.Web.UI.WebControls.Button
        Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
        Protected WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
        Protected WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
        Protected WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand
        Protected WithEvents OleDbUpdateCommand1 As System.Data.OleDb.OleDbCommand
        Protected WithEvents OleDbDeleteCommand1 As System.Data.OleDb.OleDbCommand
        Protected WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter
        Dim MyConnection As String = "provider=Microsoft.Jet.OLEDB.4.0;data source= C:\Inetpub\wwwroot\timerbutton\TechnicalSupport.mdb"
    #Region " Web Form Designer Generated Code "
    
        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
            Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
            Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand
            Me.OleDbUpdateCommand1 = New System.Data.OleDb.OleDbCommand
            Me.OleDbDeleteCommand1 = New System.Data.OleDb.OleDbCommand
            Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
            '
            'OleDbDataAdapter1
            '
            Me.OleDbDataAdapter1.DeleteCommand = Me.OleDbDeleteCommand1
            Me.OleDbDataAdapter1.InsertCommand = Me.OleDbInsertCommand1
            Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1
            Me.OleDbDataAdapter1.UpdateCommand = Me.OleDbUpdateCommand1
    
        End Sub
        Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
        Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    
        'NOTE: The following placeholder declaration is required by the Web Form Designer.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object
    
        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
    
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            Dim Connection1 As New OleDbConnection
    
            Dim SqlDataAdapter1 As New OleDbDataAdapter1
            Dim ds As New DataSet
            Dim str As String = Request.QueryString("dropdownlist1")
            Me.Connection1.ConnectionString = MyConnection
    
            Me.Connection1.Open()
            Me.SqlDataAdapter1.SelectCommand.Connection = Me.Connection1
            Me.SqlDataAdapter1.SelectCommand.CommandType = CommandType.Text
            Me.SqlDataAdapter1.SelectCommand.CommandText = "select * from School1 order by UserName WHERE UserName = '" & str
    
            Me.DataGrid1.DataSource = ds.Tables("str")
            Me.DataGrid1.ReadOnly = True
            Me.MylConnection.close()
    
            'DropDownList1.DataSource = dsSchool1.Tables("Security").DefaultView
            'DropDownList1.DataTextField = "username"
            'DropDownList1.DataValueField = "id"
    
            Label1.Text = str
    
        
    End Class

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