Populating a data grid with a stored procudure w/parameters

  • Thread starter Thread starter Machelle Chandler
  • Start date Start date
M

Machelle Chandler

All,

I'm trying to populate a datagrid with a data adapter that uses a stored
procedure with a parameter. I get the below error when I run my code
(as seen below). Any hints?

If I delete the .value = "Business Acumen" at the end of the add
parameters statement & put the below code on a different row, the error
goes away, but I get back an empty dataset.

Me.cmdUYP.Parameters("@web_competency_name").Value = "Business Acumen"

Error Msg:
The SqlParameterCollection only accepts non-null SqlParameter type
objects, not Boolean objects.


My Code:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text.RegularExpressions
Imports System.Text


Public Class UYP_Class
Inherits System.Web.UI.Page
Protected WithEvents btnFLMClose As System.Web.UI.WebControls.Button
Dim previousCat As String
Dim previousComp As String
Protected WithEvents linkIntelU As
System.Web.UI.WebControls.HyperLink
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Protected WithEvents btnClose As System.Web.UI.WebControls.Button
Protected WithEvents lnkIntelLibrary As
System.Web.UI.WebControls.HyperLink
Protected WithEvents lnkBuyOnline As
System.Web.UI.WebControls.HyperLink
Protected WithEvents conUYP As System.Data.SqlClient.SqlConnection
Protected WithEvents lblError As System.Web.UI.WebControls.Label
Protected WithEvents daUYP As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents cmdUYP As System.Data.SqlClient.SqlCommand
Protected WithEvents DsUYP1 As FDO.dsUYP
Protected WithEvents lnkAllCurric As
System.Web.UI.WebControls.HyperLink
Protected WithEvents lnkHelp As System.Web.UI.WebControls.HyperLink
Protected WithEvents dgUYP As System.Web.UI.WebControls.DataGrid
Protected WithEvents btnExportExcel As
System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.conUYP = New System.Data.SqlClient.SqlConnection()
Me.daUYP = New System.Data.SqlClient.SqlDataAdapter()
Me.cmdUYP = New System.Data.SqlClient.SqlCommand()
Me.DsUYP1 = New FDO.dsUYP()
CType(Me.DsUYP1,
System.ComponentModel.ISupportInitialize).BeginInit()
'
'conUYP
'
Me.conUYP.ConnectionString = "data source=OREA2SQL017;initial
catalog=Fin_Trng_DB;password=abcd$1234;persist se" & _
"curity info=True;user id=FinTrngUserGrp"
'
'daUYP
'
Me.daUYP.SelectCommand = Me.cmdUYP
'
'cmdUYP
'
Me.cmdUYP.CommandText = "dbo.[prc_uyp_curriculum]"
Me.cmdUYP.CommandType = System.Data.CommandType.StoredProcedure
Me.cmdUYP.Connection = Me.conUYP
Me.cmdUYP.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@web_competency_name",
System.Data.SqlDbType.NVarChar, 50).Value = "Business Acumen")

'
'DsUYP1
'
Me.DsUYP1.DataSetName = "dsUYP"
Me.DsUYP1.Locale = New System.Globalization.CultureInfo("en-US")
Me.DsUYP1.Namespace = "http://www.tempuri.org/dsUYP.xsd"
CType(Me.DsUYP1,
System.ComponentModel.ISupportInitialize).EndInit()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Try
'Me.cmdUYP.Parameters("web_competency_name").Value =
"Business Acumen"
daUYP.Fill(DsUYP1, "prc_uyp_curriculum")
If Not IsPostBack Then
dgUYP.DataSource =
DsUYP1._dbo_prc_uyp_curriculum.DefaultView()
dgUYP.DataBind()
End If
End Sub
End Class

Machelle Chandler
Intel Corporation
Beginning .NET developer
Thanks in advance for the help!
 
Hi Machelle. Try changing this
Me.cmdUYP.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@web_competency_name",
System.Data.SqlDbType.NVarChar, 50).Value = "Business Acumen")

for
Me.cmdUYP.Parameters.Add("@web_competency_name",
System.Data.SqlDbType.NVarChar, 50).Value = "Business Acumen";


Machelle Chandler said:
All,

I'm trying to populate a datagrid with a data adapter that uses a stored
procedure with a parameter. I get the below error when I run my code
(as seen below). Any hints?

If I delete the .value = "Business Acumen" at the end of the add
parameters statement & put the below code on a different row, the error
goes away, but I get back an empty dataset.

Me.cmdUYP.Parameters("@web_competency_name").Value = "Business Acumen"

Error Msg:
The SqlParameterCollection only accepts non-null SqlParameter type
objects, not Boolean objects.


My Code:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text.RegularExpressions
Imports System.Text


Public Class UYP_Class
Inherits System.Web.UI.Page
Protected WithEvents btnFLMClose As System.Web.UI.WebControls.Button
Dim previousCat As String
Dim previousComp As String
Protected WithEvents linkIntelU As
System.Web.UI.WebControls.HyperLink
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Protected WithEvents btnClose As System.Web.UI.WebControls.Button
Protected WithEvents lnkIntelLibrary As
System.Web.UI.WebControls.HyperLink
Protected WithEvents lnkBuyOnline As
System.Web.UI.WebControls.HyperLink
Protected WithEvents conUYP As System.Data.SqlClient.SqlConnection
Protected WithEvents lblError As System.Web.UI.WebControls.Label
Protected WithEvents daUYP As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents cmdUYP As System.Data.SqlClient.SqlCommand
Protected WithEvents DsUYP1 As FDO.dsUYP
Protected WithEvents lnkAllCurric As
System.Web.UI.WebControls.HyperLink
Protected WithEvents lnkHelp As System.Web.UI.WebControls.HyperLink
Protected WithEvents dgUYP As System.Web.UI.WebControls.DataGrid
Protected WithEvents btnExportExcel As
System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.conUYP = New System.Data.SqlClient.SqlConnection()
Me.daUYP = New System.Data.SqlClient.SqlDataAdapter()
Me.cmdUYP = New System.Data.SqlClient.SqlCommand()
Me.DsUYP1 = New FDO.dsUYP()
CType(Me.DsUYP1,
System.ComponentModel.ISupportInitialize).BeginInit()
'
'conUYP
'
Me.conUYP.ConnectionString = "data source=OREA2SQL017;initial
catalog=Fin_Trng_DB;password=abcd$1234;persist se" & _
"curity info=True;user id=FinTrngUserGrp"
'
'daUYP
'
Me.daUYP.SelectCommand = Me.cmdUYP
'
'cmdUYP
'
Me.cmdUYP.CommandText = "dbo.[prc_uyp_curriculum]"
Me.cmdUYP.CommandType = System.Data.CommandType.StoredProcedure
Me.cmdUYP.Connection = Me.conUYP
Me.cmdUYP.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@web_competency_name",
System.Data.SqlDbType.NVarChar, 50).Value = "Business Acumen")

'
'DsUYP1
'
Me.DsUYP1.DataSetName = "dsUYP"
Me.DsUYP1.Locale = New System.Globalization.CultureInfo("en-US")
Me.DsUYP1.Namespace = "http://www.tempuri.org/dsUYP.xsd"
CType(Me.DsUYP1,
System.ComponentModel.ISupportInitialize).EndInit()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Try
'Me.cmdUYP.Parameters("web_competency_name").Value =
"Business Acumen"
daUYP.Fill(DsUYP1, "prc_uyp_curriculum")
If Not IsPostBack Then
dgUYP.DataSource =
DsUYP1._dbo_prc_uyp_curriculum.DefaultView()
dgUYP.DataBind()
End If
End Sub
End Class

Machelle Chandler
Intel Corporation
Beginning .NET developer
Thanks in advance for the help!
 
Back
Top