参数没有默认值? [英] Parameter has no default value?

查看:338
本文介绍了参数没有默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了所有我知道的技巧来使这段代码正常工作,并且参数肯定会被赋予一个值。我想也许只有一些我没有看到的拼写错误。



I have tried every trick I know to get this code working, and the parameter is definitely being given a value. I'm thinking maybe there's just some typo that I'm not seeing.

'pulls a list of forms for the selected pokemon
Dim SqlQry As String = "SELECT [Pokemon_forms].[pokemon_id], [Pokemon].[id], [Pokemon].[identifier], [Pokemon_forms].[form_identifier] " &
    "FROM [Pokemon], [Pokemon_forms] WHERE (([Pokemon]![id]=[Pokemon_forms]![pokemon_id])) AND [Pokemon]![identifier] = ?;"

DbCommand = New OleDbCommand(SqlQry, DbConnection)
Dim IdentifierParam As New OleDbParameter("?", OleDbType.VarChar)
DbCommand.Parameters.Add(IdentifierParam)
IdentifierParam.Value = PokedexList.SelectedItems(0).Text

DbConnection.Open()

'error occurs here and states that one or more parameters has no value
Dim da As OleDbDataAdapter = New OleDbDataAdapter(SqlQry, DbConnection)

Dim ds As DataSet = New DataSet

da.Fill(ds, "Pokemon")

Dim dt As DataTable = ds.Tables("Pokemon")

Dim row As DataRow

For Each row In dt.Rows
    Dim FormIdentifier As String = row("form_identifier")

    If FormIdentifier = "" Then
        PkmFormList.Items.Add("Normal")
    Else
        FormIdentifier = StrConv(FormIdentifier, vbProperCase)

        PkmFormList.Items.Add(FormIdentifier)
    End If
Next

DbConnection.Close()





我调试时的例子是点击PokedexList中的Absol,这就是代码运行的时候。如果正确完成,它将在PkmFormList中显示一个Absol表单列表(即它应该显示Normal和Mega)。我在MS Access中运行了SqlQry,当我输入Absol作为参数值时,它按预期运行查询,但是当在vb.net中运行时,它会给出标题错误。我已经使用console.write和断点来验证IdentifierParam.Value确实是Absol,而且确实如此。有什么想法吗?



My example when I debug is to click "Absol" in the PokedexList, and that's when this code runs. If done correctly, it would bring up a list of Absol's forms in the PkmFormList (i.e. it should bring up "Normal" and "Mega"). I have run the SqlQry in MS Access and when I enter Absol as the parameter value it runs the query as expected, but when run in vb.net it gives the title error. I have used console.write and breakpoints to verify that IdentifierParam.Value is indeed Absol, and it is. Any ideas?

推荐答案

我找到了答案,它一直在我面前。



I found the answer, it was right in front of my face the whole time.

Dim da As OleDbDataAdapter = New OleDbDataAdapter(SqlQry, DbConnection)





应该是





should have been

Dim da As OleDbDataAdapter = New OleDbDataAdapter(DbCommand)


这篇关于参数没有默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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