Hello all,
I am new to VB.NET and cannot figure out how to create a dynamically generated SQL.
I have a simple test windows application with a text box (TextBox1) and a button. Upon clicking the button I would like VB to access a table in MsSQL and return values according to the text. The value is shown in a text box (txtResults) on the following form (Form2). This text should also be editable (thus a DataAdapter).
I believe that I will need to use a Connection object, Command object, and DataAdapter. I am not sure if I should let VB.NET design these objcets and do it or if I should just hand-code this information into the Form2_Load Sub. Either way...I don't know how to do it. Could somebody help me on this or know of a tutorial that covers this?
Thank you
code for Form1:
Public Class Form1
Inherits System.Windows.Forms.Form
[Windows Form Designer generated code]
Private Sub button1_click(...) Handles Button1.Click
Dim frm2 As New Form2
' strSQL is a global variable declared in a Module
strSQL = "SELECT * FROM myTable WHERE myColumn = '" & TextBox1.Text & "'"
frm2.Show()
End Sub
End Class
code for Form2:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form2
Inherits System.Windows.Forms.Form
[Windows Form Designer generated code]
Public Sub btnUpdate_Click(...) Handles...
Me.sqlDataAdapter1.Update(...)
End Sub
End Class
I am new to VB.NET and cannot figure out how to create a dynamically generated SQL.
I have a simple test windows application with a text box (TextBox1) and a button. Upon clicking the button I would like VB to access a table in MsSQL and return values according to the text. The value is shown in a text box (txtResults) on the following form (Form2). This text should also be editable (thus a DataAdapter).
I believe that I will need to use a Connection object, Command object, and DataAdapter. I am not sure if I should let VB.NET design these objcets and do it or if I should just hand-code this information into the Form2_Load Sub. Either way...I don't know how to do it. Could somebody help me on this or know of a tutorial that covers this?
Thank you
code for Form1:
Public Class Form1
Inherits System.Windows.Forms.Form
[Windows Form Designer generated code]
Private Sub button1_click(...) Handles Button1.Click
Dim frm2 As New Form2
' strSQL is a global variable declared in a Module
strSQL = "SELECT * FROM myTable WHERE myColumn = '" & TextBox1.Text & "'"
frm2.Show()
End Sub
End Class
code for Form2:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form2
Inherits System.Windows.Forms.Form
[Windows Form Designer generated code]
Public Sub btnUpdate_Click(...) Handles...
Me.sqlDataAdapter1.Update(...)
End Sub
End Class