Inquiridor
Argument not specified for parameter

Pergunta
-
Alguém tem alguma sugestão? No código abaixo a mensagem "Argument not specified for parameter " aparece na camada view conforme imagem:
Imports System.Data.Common
Imports System.Data.SqlClient
Imports WRB.Data
Public Class ClassModel3_Endereco
Dim a_id_pf As Integer
Dim a_sigla As String
Dim a_NUMNOME As String
Dim a_cod_endereco As Integer
Dim a_DESCRICAO As String
Public Function busca_end_pf(ByVal id_pf)
Dim DT_pf_end As DataTable
Dim comando As String
comando = "SELECT sigla + ' ' + logradouro + ',' + numero + ' - ' + MUNNOME as DESCRICAO, cod_endereco FROM tb_cad_endereco A, tb_ref_reg_mun B, tb_ref_reg_logradouro_tipo C, tb_cad_pf_endereco D, tb_cad_pf E WHERE A.cod_mun = B.MUNCOD and A.cod_tipo = C.id_tipo_end AND A.id_cad_endereco = D.cod_endereco and E.id_pf = @Par1 ORDER BY sigla,logradouro,numero"
Dim param As ArrayList = New ArrayList()
param.Add(id_pf)
DT_pf_end = ClassData1_SelReaderCparam.sel(comando, param)
For Each linha In DT_pf_end.Rows
a_id_pf = id_pf
a_cod_endereco = linha("cod_endereco")
a_DESCRICAO = linha("DESCRICAO")
Next
Return DT_pf_end
End Function
Public Property id_pf() As Integer
Get
Return a_id_pf
End Get
Set(ByVal value As Integer)
a_id_pf = value
End Set
End Property
Public Property sigla() As String
Get
Return a_sigla
End Get
Set(ByVal value As String)
a_sigla = value
End Set
End Property
Public Property NUMNOME() As String
Get
Return a_NUMNOME
End Get
Set(ByVal value As String)
a_NUMNOME = value
End Set
End Property
Public Property cod_endereco() As Integer
Get
Return a_cod_endereco
End Get
Set(ByVal value As Integer)
a_cod_endereco = value
End Set
End Property
Public Property DESCRICAO() As String
Get
Return a_DESCRICAO
End Get
Set(ByVal value As String)
a_DESCRICAO = value
End Set
End Property
End Class
Imports System.Data.SqlClient
Public Class ClassData1_SelReaderCparam
Public Shared Function sel(ByVal comando As String, ByVal param As ArrayList) As DataTable
Dim objDR As SqlDataReader
Dim Data_DataTable As DataTable = New DataTable()
Using CN As SqlConnection = New SqlConnection()
Try
CN.ConnectionString = My.Settings.cn1
Dim com As SqlCommand = New SqlCommand()
com.CommandText = comando
com.CommandType = CommandType.Text
Dim c As Integer = 0
For Each item In param
c += 1
com.Parameters.Add(String.Format("@Par{0}", c), GetDBType(item.GetType())).Value = item
Next
com.Connection = CN
CN.Open()
objDR = com.ExecuteReader(CommandBehavior.CloseConnection)
Data_DataTable.Load(objDR)
CN.Close()
Return Data_DataTable
Catch ex As Exception
'...................... colocar tratamento de erros
'
End Try
Return Data_DataTable
End Using
End Function
Public Shared Function GetDBType(ByVal theType As System.Type) As SqlDbType
Dim param As SqlParameter = New SqlParameter()
Dim tc As System.ComponentModel.TypeConverter
tc = System.ComponentModel.TypeDescriptor.GetConverter(param.DbType)
If tc.CanConvertFrom(theType) Then
param.DbType = tc.ConvertFrom(theType.Name)
End If
Return param.SqlDbType
End Function
End Class
Todas as Respostas
-
Alguém tem alguma sugestão? No código abaixo a mensagem "Argument not specified for parameter " aparece na camada view conforme imagem:
Imports System.Data.Common
Imports System.Data.SqlClient
Imports WRB.Data
Public Class ClassModel3_Endereco
Dim a_id_pf As Integer
Dim a_sigla As String
Dim a_NUMNOME As String
Dim a_cod_endereco As Integer
Dim a_DESCRICAO As String
Public Function busca_end_pf(ByVal id_pf)
Dim DT_pf_end As DataTable
Dim comando As String
comando = "SELECT sigla + ' ' + logradouro + ',' + numero + ' - ' + MUNNOME as DESCRICAO, cod_endereco FROM tb_cad_endereco A, tb_ref_reg_mun B, tb_ref_reg_logradouro_tipo C, tb_cad_pf_endereco D, tb_cad_pf E WHERE A.cod_mun = B.MUNCOD and A.cod_tipo = C.id_tipo_end AND A.id_cad_endereco = D.cod_endereco and E.id_pf = @Par1 ORDER BY sigla,logradouro,numero"
Dim param As ArrayList = New ArrayList()
param.Add(id_pf)
DT_pf_end = ClassData1_SelReaderCparam.sel(comando, param)
For Each linha In DT_pf_end.Rows
a_id_pf = id_pf
a_cod_endereco = linha("cod_endereco")
a_DESCRICAO = linha("DESCRICAO")
Next
Return DT_pf_end
End Function
Public Property id_pf() As Integer
Get
Return a_id_pf
End Get
Set(ByVal value As Integer)
a_id_pf = value
End Set
End Property
Public Property sigla() As String
Get
Return a_sigla
End Get
Set(ByVal value As String)
a_sigla = value
End Set
End Property
Public Property NUMNOME() As String
Get
Return a_NUMNOME
End Get
Set(ByVal value As String)
a_NUMNOME = value
End Set
End Property
Public Property cod_endereco() As Integer
Get
Return a_cod_endereco
End Get
Set(ByVal value As Integer)
a_cod_endereco = value
End Set
End Property
Public Property DESCRICAO() As String
Get
Return a_DESCRICAO
End Get
Set(ByVal value As String)
a_DESCRICAO = value
End Set
End Property
End Class
Imports System.Data.SqlClient
Public Class ClassData1_SelReaderCparam
Public Shared Function sel(ByVal comando As String, ByVal param As ArrayList) As DataTable
Dim objDR As SqlDataReader
Dim Data_DataTable As DataTable = New DataTable()
Using CN As SqlConnection = New SqlConnection()
Try
CN.ConnectionString = My.Settings.cn1
Dim com As SqlCommand = New SqlCommand()
com.CommandText = comando
com.CommandType = CommandType.Text
Dim c As Integer = 0
For Each item In param
c += 1
com.Parameters.Add(String.Format("@Par{0}", c), GetDBType(item.GetType())).Value = item
Next
com.Connection = CN
CN.Open()
objDR = com.ExecuteReader(CommandBehavior.CloseConnection)
Data_DataTable.Load(objDR)
CN.Close()
Return Data_DataTable
Catch ex As Exception
'...................... colocar tratamento de erros
'
End Try
Return Data_DataTable
End Using
End Function
Public Shared Function GetDBType(ByVal theType As System.Type) As SqlDbType
Dim param As SqlParameter = New SqlParameter()
Dim tc As System.ComponentModel.TypeConverter
tc = System.ComponentModel.TypeDescriptor.GetConverter(param.DbType)
If tc.CanConvertFrom(theType) Then
param.DbType = tc.ConvertFrom(theType.Name)
End If
Return param.SqlDbType
End Function
End ClassComplementando:
Private Sub carga_busca_cliente()
Dim DTpf As New ClassModel4_pf()
DropDownList4_busca_cliente.Items.Clear()
DropDownList4_busca_cliente.DataSource = DTpf.pf
DropDownList4_busca_cliente.DataTextField = ("nome_completo")
DropDownList4_busca_cliente.DataValueField = ("id_pf")
DropDownList4_busca_cliente.DataBind()
DropDownList4_busca_cliente.Items.Insert(0, "Selecione opção abaixo")
DropDownList4_busca_cliente.SelectedIndex = 0
DropDownList4_busca_cliente.ForeColor = Drawing.Color.Black
End Sub -
Não acha que está faltando passar um parâmetro para o método?
- Sugerido como Resposta Diego de Almeida Barreto (Lewis) domingo, 7 de julho de 2013 14:33
-
-
Wilson Boris, Esta equivocado.....
pois vc passa o parâmetro no Dtpf_end e duas linhas abaixo tenta chamar o objeto no datasource sem paramentro !!!!!!!!!!!!!!!!!!!!!
Diego Almeida Barreto System Analyst / Software Developer