I 'm new At visual studio and i wish to allow the user enter something in to the query
i.e look for an worker I'll use
Choose * From Worker Where ID = (i would like the consumer to go in the worthiness here)
i already connected the database
and that i know i'm able to obtain the value from the text box however i really do not understand how to put that value within the query directly and refer to it as immediately
we do hope you understand what i'm saying and sorry for bad British :/
Parameterizing is comparatively simple.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click ExecuteSQL("Data Source=Server;Initial Catalog=Database;Persist Security Info=True;Integrated Security=True", _ "Select * From Employee Where ID=@id", New SqlClient.SqlParameter("@id", 123)) End Sub Public Function ExecuteSQL(ByVal Connection As String, _ ByVal SQL As String, _ ByRef Param As SqlClient.SqlParameter) As System.Data.DataTable Try Dim dt As System.Data.DataTable = Nothing Dim SqlRdr As SqlClient.SqlDataReader Using SqlConn As SqlClient.SqlConnection = New SqlClient.SqlConnection(Connection) Using SqlCmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(SQL, SqlConn) SqlCmd.CommandType = CommandType.Text SqlCmd.Parameters.Add(Param) SqlConn.Open() SqlRdr = SqlCmd.ExecuteReader() Try If SqlRdr.IsClosed = False AndAlso SqlRdr.HasRows = True Then dt = New System.Data.DataTable dt.BeginLoadData() dt.Load(SqlRdr) dt.EndLoadData() End If Finally If SqlRdr IsNot Nothing Then SqlRdr.Close() End If End Try End Using End Using Return dt Catch ex As Exception Return Nothing End Try End Function