具有多个参数的VB 2010-SQL语句. [英] VB 2010-SQL Statement with multiple parameters.

查看:78
本文介绍了具有多个参数的VB 2010-SQL语句.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.

我有这段代码:

Hello.

I have this piece of code:

<pre lang="vb">Dim conz As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Bdados\CV_PARTS.accdb;Persist Security Info=False";)
            Dim cmd As New OleDbCommand("SELECT * FROM PECAS_IN WHERE Fornecedor = ? and Criado between ? and ? AND Peca = ", conz)
            Dim da As New OleDb.OleDbDataAdapter(cmd)
            Dim ds As New DataSet
            conz.Open()
            Dim P1 As New OleDbParameter
        cmd.Parameters.AddWithValue("P1", Me.ComboBox1.Text)
            Dim P2 As New OleDbParameter
        cmd.Parameters.AddWithValue("P2", Me.DateTimePicker1.Value)
        Dim P3 As New OleDbParameter
        cmd.Parameters.AddWithValue("P3", Me.DateTimePicker2.Value)
            Dim P4 As New OleDbParameter
            cmd.Parameters.AddWithValue("P4", Me.ComboBox1.Text)
            da.Fill(ds)
            conz.Close()
            Entrada_Pecas_Grid.PECAS_INDataGridView.DataSource = ds.Tables(0)
            Entrada_Pecas_Grid.Show()
            ds = Nothing




它对于第一个参数工作正常,但会忽略其余部分而不会出错."Criado"字段是采用"dd-mmm-yyy"格式的日期字段.当我在Me.DateTimePicker1.Value上进行监视时,它会显示值:




It works fine for the first parameter but ignores the rest without erroring The "Criado" field is a date field with "dd-mmm-yyy" format. When i make a watch on the Me.DateTimePicker1.Value it shows the value:

#6/22/2011 5:27:37 PM#


这可能是查询失败的原因吗?如果是,有人可以让我知道如何解决该问题吗?
感谢您的帮助.

Octavio


Can this be the reason why the query is failing? If yes, can someone please let me know how can i solve the problem?
Thanks is advance for any help.

Octavio

推荐答案

Dim P3 As New OleDbParameter
      cmd.Parameters.AddWithValue("P3", Me.DateTimePicker2.Value)



您的参数未添加,您将名称用引号引起来.肯定不对吗?



Your parameters are not being added, you''re putting the names in quotes. Surely that''s not right ?


这篇关于具有多个参数的VB 2010-SQL语句.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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