停止SQL输入 [英] stopping SQL for input

查看:95
本文介绍了停止SQL输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将PL / SQL开发人员转换为VB Studio SQL。



在PL / SQL中我可以执行:



Trying to convert PL/SQL developer into VB Studio SQL.

In PL/SQL I can execute:

AND TO_CHAR(SUBSTR(CM.DATA,to_char(instr(cm.data,'^^^')+3),4)) = &chute







当执行SQL时,弹出窗口将允许我输入滑槽编号,数据是填充。



只是寻找VB等效。




When SQL is executed a popup will allow me to enter chute number and data is populated.

Just looking for VB equivilent.

推荐答案

没有像PL /那样的popup VB .NET代码中的SQL语句中的SQL。



用户输入要在表单上的TextBox中找到的值。您使用该TextBox值作为SQL语句的参数。在我的示例中,我从TextBox值的开头和结尾修剪空格,因为有时用户会意外地输入它们。



@CHUTE在下面的SQL语句中是占位符参数。

参数值被放入SqlParameter对象中。 SqlParameter对象被添加到SqlCommand对象。



这是一个例子:



There is no "popup" like PL/SQL in SQL statements in VB .NET code.

Your user enters the value to be found in a TextBox on the form. You use that TextBox value as a parameter to the SQL statement. In my example, I trim spaces from the beginning and end of the TextBox value because sometimes users accidentally enter them.

@CHUTE in the SQL statement below is the placeholder for the parameter.
The parameter value is put into a SqlParameter object. The SqlParameter object is added to the SqlCommand object.

Here is an example:

Dim cn As New SqlConnection
Dim obCommand As SqlCommand
Dim rs As SqlDataReader

''.... open the connection ...
cn.ConnectionString = "Your Connection String"
cn.Open()

...


Dim obCommand As SqlCommand
Const SQL_SELECT As String = "SELECT col1,col2,col3 FROM table1 WHERE col1=@CHUTE;"
obCommand = New SqlCommand(SQL_SELECT, cn) '' Instantiate SqlCommand object
Dim obParm As New SqlParameter
Dim strChute As String=TextBox1.Text.Trim '' Remove front and back spaces
Try
   obParm.ParameterName = "CHUTE"     '' Name of @ parameter in the SQL statement
   obParm.SqlDbType = SqlDbType.NVarChar '' Data Type
   obParm.Size = strChute.Length      '' Size of parameter
   obParm.Value = strChute            '' Parameter value
   obCommand.Parameters.Add(obParm)   '' Add to SqlCommand object
   obParm = Nothing
   rs = obCommand.ExecuteReader       '' Execute SQL statement
   If rs.HasRows Then
       While rs.Read                  '' Retrieve a row
           ...
           ...
           ...
       End While
   End If
 Catch myException As SqlException
    Call ShowSQLException(myException)
 Catch myException As Exception
    MsgBox(myException.Message, MsgBoxStyle.Critical, "Caption")
 Finally
    Try
       rs.Close()
    Catch
    End Try
    Try
       rs.Dispose()
    Catch
    End Try
    Try
       obCommand.Dispose()
    Catch
    End Try
 End Try


这篇关于停止SQL输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆