我尝试使用下面的查询SQL查询的帮助请求
Dim sqlQry As String = "SELECT * FROM tblTest where [email protected] and [email protected]"
然后我填我的DataAdapter通过
Dim dAdt As New SqlDataAdapter(sqlQry, conStr)
但不知道往哪里放,我以后在那里设置的参数条款。
我尝试使用下面的查询SQL查询的帮助请求
Dim sqlQry As String = "SELECT * FROM tblTest where [email protected] and [email protected]"
然后我填我的DataAdapter通过
Dim dAdt As New SqlDataAdapter(sqlQry, conStr)
但不知道往哪里放,我以后在那里设置的参数条款。
您可以使用像这样的参数:
Dim adapter As SqlDataAdapter = New SqlDataAdapter()
' Create the SelectCommand.
Dim command As SqlCommand = New SqlCommand("SELECT * FROM tblTest where [email protected] and [email protected]", connection)
' Add the parameters for the SelectCommand.
command.Parameters.Add("@NM", SqlDbType.NVarChar, 15)
command.Parameters.Add("@RN", SqlDbType.NVarChar, 15)
adapter.SelectCommand = command
创建参数
SqlParameter param = new SqlParameter();
param.ParameterName = "@RN";
param.Value = inputCity;
然后帕拉姆添加到您的SQL命令。
SqlCommand cmd = new SqlCommand();
cmd.Parameters.Add(param);
这并不显示该命令如何与数据适配器一起使用 –
如果用户不愿意智能地查看答案并尝试理解它,那么这是他们自己制造的问题。这是一个快速的2分钟的答案,因为这是需要多少研究才能找出答案。如果你想要一个教程,然后去阅读教程。 – BentOnCoding
如果我理解你的要求,你需要创建一个SqlCommand的实例和使用您的sqlQry与此。然后使用SqlCommand.Parameters.Add()或SqlCommand.Parameters.AddWithValue()添加您的参数。使用SqlCommand而不是您创建的字符串初始化您的SqlDataAdapter。
Using connection As New SqlConnection(conStr)
Dim command As New SqlCommand(sqlQry, connection)
command.Parameters.Add("@NM", SqlDbType.NVarChar, 100).Value="Your Value"
command.Parameters.AddWithValue("@RN", "Your Value")
Dim adapter As New SqlDataAdapter(command)
adapter.Fill(dataSet)
Return dataSet
End Using
这个问题与ASP.NET有什么关系? –
这就是我想要使用它的地方 –
但这与问题无关。无论你想在ASP.NET中还是在Windows服务中使用它,问题都是一样的。 –