none
Run Time Prograing RRS feed

  • Question

  • hi

    can i make a button, text box etc at run time and perform  function, then disappear.  i do not want to create multiple form i want in one form text box appear take northwind supplier data add in database or customer order product etc in one form not to create multiple form is it possible.

    thanks 


    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959

    Thursday, July 11, 2019 3:26 AM

All replies

  • Hi,

    I don’t understand what is north wind supplier data add in database or customer order product etc in one form not to create multiple form is it possible,you better explain it again.Do you want the following effect?

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim btn1 As New Button() With {.Location = New Point(10, 40), .Text = "btn1"}
            Dim tb1 As New TextBox() With {.Location = New Point(10, 10)}
            Me.Controls.Add(btn1)
            Me.Controls.Add(tb1)
            AddHandler btn1.Click, Sub()
                                       '........
                                       Me.Controls.Remove(btn1)
                                       Me.Controls.Remove(tb1)
                                   End Sub
        End Sub
    End Class
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 11, 2019 5:23 AM
    Moderator
  • hi

    thanks for reply, i want to insert data into sql server via vb.net, when ever i want perform any data base operation like insert, update , and delete.  a main form ask me to select operation on database,  after that according to the requirement the text box  appear and perform operation and all end.

    currently i made the form data insert form, data update form , data delte form.  when perform insert and update particular text box appear and in delete id text box appear .  i see your code i can not under stand this line

     AddHandler btn1.Click, Sub()

    when we make a runtime insert button how to write the code or make the event to insert data in the sql server

    in manual case drage a button double click on it make a insert code in sub like

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    
        End Sub
    in run time same case to handle button event.


    MUHAMMAD ANZAR E-mail : muhammadanzar@hotmail.com Mobile # :0092-3215096959


    Thursday, July 11, 2019 7:06 AM
  • Hi,

      AddHandler btn1.Click, Sub()
     
                                   End Sub

    click Btn to trigger the sub 

    my code:

    Imports System.Data.SqlClient
    
    Public Class Form1
        Dim btn1 As Button
        Dim tb1 As TextBox
        Dim tb2 As TextBox
        Dim tb3 As TextBox
        Dim tb4 As TextBox
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            btn1 = New Button() With {.Location = New Point(10, 40), .Text = "btn1"}
            tb1 = New TextBox() With {.Location = New Point(10, 10)}
            tb2 = New TextBox() With {.Location = New Point(160, 10)}
            tb3 = New TextBox() With {.Location = New Point(310, 10)}
            tb4 = New TextBox() With {.Location = New Point(460, 10)}
            Me.Controls.Add(btn1)
            Me.Controls.Add(tb1)
            Me.Controls.Add(tb2)
            Me.Controls.Add(tb3)
            Me.Controls.Add(tb4)
            AddHandler btn1.Click, Sub()
                                       Using conn = New SqlConnection(constr)
                                           conn.Open()
                                           cmd = New SqlCommand("insert into invoice values(@tb1,@tb2,@tb3,@tb4 )", conn)
                                           cmd.Parameters.AddWithValue("@tb1", tb1.Text)
                                           cmd.Parameters.AddWithValue("@tb2", tb2.Text)
                                           cmd.Parameters.AddWithValue("@tb3", tb3.Text)
                                           cmd.Parameters.AddWithValue("@tb4", tb4.Text)
                                           cmd.ExecuteNonQuery()
    
                                       End Using
    
                                       Me.Controls.Remove(btn1)
                                       Me.Controls.Remove(tb1)
                                       Me.Controls.Remove(tb2)
                                       Me.Controls.Remove(tb3)
                                       Me.Controls.Remove(tb4)
                                   End Sub
        End Sub
    End Class

    insert database:

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, July 11, 2019 7:46 AM
    Moderator