locked
How to convert Desktop app to Web app using VB.Net. RRS feed

  • Question

  • User-1306088796 posted

    Hi everyone!

    I am new to programming, I have built a Desktop app in VB.Net that works perfectly, now I would like to convert it onto a Website, I know its not going to be easy but day one and it already seems to be a impossible task!!!

    I am trying a simple task, trying to load DropDownList for Sql DataBase,the first part of my code works ok but second not, can anyone help please! Here is my code.

    Oh the second dropdown needs to enter values from what ever is in first dropdown, if that makes sense.

    Thanks

    Imports System.Data.SqlClient
    Imports System.Data

    Partial Class Service_Manuals
    Inherits System.Web.UI.Page
    Dim SQLCon As New SqlConnection With {.ConnectionString = "Server=desktop-bi7l3hl\sqlexpress;Database=Cb_Radio_Data;User=sa;Pwd=keyn48"}


    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim SQLCmd As New SqlCommand("SELECT Manufacturer FROM Cb_Radios GROUP BY Manufacturer", SQLCon)
    Dim SQLda As New SqlDataAdapter(SQLCmd)
    Dim SQLdt As New DataTable()
    SQLda.Fill(SQLdt)
    DropDownList_Manu.DataTextField = "Manufacturer"

    DropDownList_Manu.DataSource = SQLdt
    DropDownList_Manu.DataBind()

    End Sub
    Protected Sub DropDownList_Manu_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList_Manu.SelectedIndexChanged
    Dim SQLCmd2 As New SqlCommand("SELECT Model FROM Cb_Radios WHERE Manufacturer = '" & DropDownList_Manu.Text & "'Group by Model", SQLCon)
    Dim SQLda2 As New SqlDataAdapter(SQLCmd2)
    Dim SQLdt2 As New DataTable()
    SQLda2.Fill(SQLdt2)
    DropDownList_Model.DataTextField = "Model"

    DropDownList_Model.DataSource = SQLdt2
    DropDownList_Model.DataBind()
    End Sub

    Thursday, January 11, 2018 6:33 PM

All replies

  • User753101303 posted

    Hi,

    How a desktop app and a web site app is really different. The best you could do is that by isolating non UI related code so that it could be more easily reused but the whole UI part should be basically considered as a full rewrite.

    Edit: in particular the HUGE difference is that the web is "stateless" ie unlike a desktop app where a form is created and stay in memory as long as the user is using it, for the web a new "form" is created for each web request. The purpose of this "form" is to generate HTML markup that is sent back and rendered by the browser and at this step this server side "form" doesn"t exists any more (its only purpose is to render HTML markup to browser).

    How many forms to you have ?

    Thursday, January 11, 2018 6:39 PM
  • User2103319870 posted

    keynaboutradios

    trying to load DropDownList for Sql DataBase,the first part of my code works ok but second not, can anyone help please!

    You are loading the first dropdownlist with data on every postback so the selected value will get reset on each postback. Try loading data inside if not postback  block like below

     Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            If Not IsPostBack Then
                Dim SQLCmd As New SqlCommand("SELECT Manufacturer FROM Cb_Radios GROUP BY Manufacturer", SQLCon)
                Dim SQLda As New SqlDataAdapter(SQLCmd)
                Dim SQLdt As New DataTable()
                SQLda.Fill(SQLdt)
                DropDownList_Manu.DataTextField = "Manufacturer"
    
                DropDownList_Manu.DataSource = SQLdt
                DropDownList_Manu.DataBind()
            End If
        End Sub

    Thursday, January 11, 2018 6:43 PM
  • User-1306088796 posted

    I have tried that and still not working!

    I hope the post made sense, DropDownList_Manu_SelectedIndexChange shows only Models that are from the Manufacturer I choose once I select a Manufacturer from list.

    Thanks

    Thursday, January 11, 2018 6:56 PM
  • User-1306088796 posted

    Thanks 

    I sort of understand, with the little knowledge I have.

    I am sat in front of both screens and making new UI to suit the code, and from I understand you are saying that there is very little memory so each time a user does a action it asks server again for the code. Is that right???

    Thursday, January 11, 2018 7:07 PM
  • User-707554951 posted

    Hi keynaboutradios

    Yes, we will ask server again very time a post back occurs.

    Your code seems to implement cascading dropdownlist.

    So dropdownlist(DropDownList_Model ) shows only Models for Manufacture you choose from DropDownList_Manu list.

    You will get better understanding and a good sample by referring to the links below:

    https://www.aspsnippets.com/Articles/Creating-Cascading-DropDownLists-in-ASP.Net.aspx

    Best regards

    Cathy

    Friday, January 12, 2018 7:27 AM