Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the parameter query code below gives error at da.Fill(dt)
error message is (A parameter is missing. [parameter ordinal 1])
when I take out the where clause the code works
but I need to filter. please help



Dim conn As New SqlCeConnection()
        Dim connect As String = "Persist Security Info = False; Data Source=|DataDirectory|\POSadmini.sdf;"
        conn.ConnectionString = connect
        conn.Open()
        Dim bna As Integer = 17
        Dim query As String = "SELECT * from tblbranch where branchcode = @cod "
        Dim bcmd As New SqlCeCommand(query, conn)
        bcmd.Parameters.AddWithValue("@cod", bna)
        Dim da As New SqlCeDataAdapter(query, conn)
        Dim dt As New DataTable
        da.Fill(dt)
        bcmd.ExecuteNonQuery()
Posted
Comments
Abdul Samad KP 11-Sep-14 1:44am    
Change the line Dim da As New SqlCeDataAdapter(query, conn)
to Dim da As New SqlCeDataAdapter(bcmd, conn)

1 solution

Um.
You create a command, you add parameters, then... You don't use it to build you DataAdapter. Instead, you build it from the original string, without the parameter you need to supply.

Remove the line:
bcmd.ExecuteNonQuery()

And use the command object to build the DataAdapter:
Dim da As New SqlCeDataAdapter(bcmd)
 
Share this answer
 
Comments
Member 10316149 11-Sep-14 2:14am    
thanks you save my day

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900