In the project, select the database adapter in the "Toolbox" in the project, this example is an ODBC data source, so select ODBCDataAdapter. Select ODBCDataAdapter, select SelectCommand, select SELECTCOMMAND, expand, select Connection, select "New" in the drop-down box In the pop-up window, select the Computer Database page, select the odbcdataserce. Select Command Text, click the "Optional button" next to it, enter the SQL statement in the pop-up window. If there is conditional parameters in the SQL statement, use "Question mark?" Instead. Such as: select user, name from table where user =?. And you need to select Parameters, click the "Optional No" button next to it, select "Add" in the pop-up window, add a parameter. Modify the properties of the parameter in the attribute box next to it. ODBCTYPE is the type of parameter corresponding field, and SourceColumn is the parameter corresponding field name. ParameterName is the parameter name, here for param1.
Let's go to the code page, manually modify the code. When configuring ODBCDataAdapter, after the new connection is created, there is a connection control generated display. The name is ODBCCONNECTION. When the database is connected, it will open it first. Use the statement me.odbcconnection1.open (), using me.odbcconnection1.close ().
Data queries can be placed in a place equivalent to a recordset, where the variable ODR1 is defined in the statement Dim Odr1 as system.data.odbc.odbcdataReader to store.
Just said, the query has a parameter, now you want to pass the actual value obtained from the interface to the parameters, use the statement me.odbcselectcommand2.parameters ("param1"). Value = me.textBox1.text, here, here is ODBCSELECTCOMMAND, Not odbcdataadapter2.selectcommand. Then do the following statement to get the record set = me.odbcdataadapter2.selectCommand.executeReader () Judgment the record set is empty, not empty, read the record set through the ODR1 ("Field Name") IF Odr1.hasRows Then While odr1.read () name = odr1 ("name") user = odr1 ("user") end whilend ifodr1.close ()