Ask a Question related to ASP.NET General, Design and Development.
-
Rob Wire #1
DDL values with DataReader and stored procedures
For the code below, how could I add an item in the drop
down lists for both company and location to be an "All"
selection that would send to the stored proc.
spRptAttachments a value of "%" so that it would bring
back all attachments at all companies or all locations at
a company? Thank you, Rob.
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim cmd As System.Data.SqlClient.SqlCommand
cmd = New System.Data.SqlClient.SqlCommand
("Web_CompanyList", Me.SqlConnection1)
cmd.CommandType = CommandType.StoredProcedure
Me.SqlConnection1.Open()
Dim myDataReader As
System.Data.Sqlclient.SqlDataReader = cmd.ExecuteReader
(CommandBehavior.CloseConnection)
ddlCompany.DataSource = myDataReader
ddlCompany.DataValueField = "CompanyID"
ddlCompany.DataTextField = "CompanyName"
ddlCompany.DataBind()
ddlCompany_SelectedIndexChanged(Nothing,
Nothing)
End If
End Sub
Private Sub ddlCompany_SelectedIndexChanged(ByVal
sender As System.Object, ByVal e As System.EventArgs)
Handles ddlCompany.SelectedIndexChanged
Dim param As System.Data.SqlClient.SqlParameter
Dim cmd As System.Data.SqlClient.SqlCommand
Dim intCompanyID As Integer
cmd = New System.Data.SqlClient.SqlCommand
("WEB_GetLocationFromCompanyID", Me.SqlConnection1)
cmd.CommandType = CommandType.StoredProcedure
param = cmd.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CompanyID",
SqlDbType.Int))
param.Direction = ParameterDirection.Input
' ********Selected Value of Option List*******
param.Value = ddlCompany.Items
(ddlCompany.SelectedIndex).Value
Me.SqlConnection1.Open()
Dim myDataReader As
System.Data.Sqlclient.SqlDataReader = cmd.ExecuteReader
(CommandBehavior.CloseConnection)
ddlLocation.DataSource = myDataReader
ddlLocation.DataValueField = "CompanyLocationID"
ddlLocation.DataTextField = "CoLo"
ddlLocation.DataBind()
End Sub
Private Sub btnSearch_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnSearch.Click
Dim prmDateFrom As
System.Data.SqlClient.SqlParameter
Dim prmCoID As System.Data.SqlClient.SqlParameter
Dim prmColo As System.Data.SqlClient.SqlParameter
Dim cmd As System.Data.SqlClient.SqlCommand
Dim intCompanyID As Integer
cmd = New System.Data.SqlClient.SqlCommand
("spRptAttachments", Me.SqlConnection1)
cmd.CommandType = CommandType.StoredProcedure
prmDateFrom = cmd.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@DateFrom",
SqlDbType.DateTime))
prmCoID = cmd.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CompanyID",
SqlDbType.Int))
prmColo = cmd.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CompanyLocati onID",
SqlDbType.Int))
prmDateFrom.Direction = ParameterDirection.Input
prmCoID.Direction = ParameterDirection.Input
prmColo.Direction = ParameterDirection.Input
' ********Selected Value of Option List*******
prmDateFrom.Value = tbDateFrom.Text
prmCoID.Value = ddlCompany.Items
(ddlCompany.SelectedIndex).Value
prmColo.Value = ddlLocation.Items
(ddlLocation.SelectedIndex).Value
Me.SqlConnection1.Open()
Dim myDataReader As
System.Data.Sqlclient.SqlDataReader = cmd.ExecuteReader
(CommandBehavior.CloseConnection)
DataGrid1.DataSource = myDataReader
DataGrid1.DataBind()
End Sub
Rob Wire Guest
-
Stored Procedures
Hi all, I'm a little confused about how to obtain a result set from a stored procedure (stored in a Visual FoxPro 8.0 database) from an ASP.NET... -
dt_ Stored Procedures
Please could you tell me if it is safe to remove the dt_ stored procedures from my database? I have spent some time searching the web/groups for... -
New to ASP and Stored Procedures
Hi I have some experince with ASP and databases in General, however Stored Procedures are new. I need to call a stored procedure and have bene... -
PHP and returned values from Informix stored procedures
Does anyone know how to retrieve the values returned from an Informix Stored procedure in PHP. I have a procedure that returns 4 values but only... -
Stored Procedures and 4GL
Hello, I am using Informix 7 se database. Is it possible to call a 4GL program from a stored procedure? Thanks Ahmer -
Eric Wise #2
Re: DDL values with DataReader and stored procedures
After you bind your dropdownlist and close the datareader just do an
items.insert "Select All" at position 0. Next line would be to set
items(0).value to % or whatever character you want.
(Note sometimes I do "Choose One" as my position 0 with a value of empty
string "" so I can use a required field validator. Same concept)
Hope this helps.
"Rob Wire" <STS@hotmail.com> wrote in message
news:8e2e01c35b64$9c7a8c00$a001280a@phx.gbl...> For the code below, how could I add an item in the drop
> down lists for both company and location to be an "All"
> selection that would send to the stored proc.
> spRptAttachments a value of "%" so that it would bring
> back all attachments at all companies or all locations at
> a company? Thank you, Rob.
>
> Private Sub Page_Load(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles MyBase.Load
> If Not IsPostBack Then
> Dim cmd As System.Data.SqlClient.SqlCommand
> cmd = New System.Data.SqlClient.SqlCommand
> ("Web_CompanyList", Me.SqlConnection1)
> cmd.CommandType = CommandType.StoredProcedure
> Me.SqlConnection1.Open()
> Dim myDataReader As
> System.Data.Sqlclient.SqlDataReader = cmd.ExecuteReader
> (CommandBehavior.CloseConnection)
> ddlCompany.DataSource = myDataReader
> ddlCompany.DataValueField = "CompanyID"
> ddlCompany.DataTextField = "CompanyName"
> ddlCompany.DataBind()
> ddlCompany_SelectedIndexChanged(Nothing,
> Nothing)
> End If
> End Sub
>
> Private Sub ddlCompany_SelectedIndexChanged(ByVal
> sender As System.Object, ByVal e As System.EventArgs)
> Handles ddlCompany.SelectedIndexChanged
> Dim param As System.Data.SqlClient.SqlParameter
> Dim cmd As System.Data.SqlClient.SqlCommand
> Dim intCompanyID As Integer
> cmd = New System.Data.SqlClient.SqlCommand
> ("WEB_GetLocationFromCompanyID", Me.SqlConnection1)
> cmd.CommandType = CommandType.StoredProcedure
> param = cmd.Parameters.Add(New
> System.Data.SqlClient.SqlParameter("@CompanyID",
> SqlDbType.Int))
> param.Direction = ParameterDirection.Input
> ' ********Selected Value of Option List*******
> param.Value = ddlCompany.Items
> (ddlCompany.SelectedIndex).Value
> Me.SqlConnection1.Open()
> Dim myDataReader As
> System.Data.Sqlclient.SqlDataReader = cmd.ExecuteReader
> (CommandBehavior.CloseConnection)
> ddlLocation.DataSource = myDataReader
> ddlLocation.DataValueField = "CompanyLocationID"
> ddlLocation.DataTextField = "CoLo"
> ddlLocation.DataBind()
> End Sub
>
> Private Sub btnSearch_Click(ByVal sender As
> System.Object, ByVal e As System.EventArgs) Handles
> btnSearch.Click
> Dim prmDateFrom As
> System.Data.SqlClient.SqlParameter
> Dim prmCoID As System.Data.SqlClient.SqlParameter
> Dim prmColo As System.Data.SqlClient.SqlParameter
> Dim cmd As System.Data.SqlClient.SqlCommand
> Dim intCompanyID As Integer
> cmd = New System.Data.SqlClient.SqlCommand
> ("spRptAttachments", Me.SqlConnection1)
> cmd.CommandType = CommandType.StoredProcedure
> prmDateFrom = cmd.Parameters.Add(New
> System.Data.SqlClient.SqlParameter("@DateFrom",
> SqlDbType.DateTime))
> prmCoID = cmd.Parameters.Add(New
> System.Data.SqlClient.SqlParameter("@CompanyID",
> SqlDbType.Int))
> prmColo = cmd.Parameters.Add(New
> System.Data.SqlClient.SqlParameter("@CompanyLocati onID",
> SqlDbType.Int))
> prmDateFrom.Direction = ParameterDirection.Input
> prmCoID.Direction = ParameterDirection.Input
> prmColo.Direction = ParameterDirection.Input
> ' ********Selected Value of Option List*******
> prmDateFrom.Value = tbDateFrom.Text
> prmCoID.Value = ddlCompany.Items
> (ddlCompany.SelectedIndex).Value
> prmColo.Value = ddlLocation.Items
> (ddlLocation.SelectedIndex).Value
> Me.SqlConnection1.Open()
> Dim myDataReader As
> System.Data.Sqlclient.SqlDataReader = cmd.ExecuteReader
> (CommandBehavior.CloseConnection)
> DataGrid1.DataSource = myDataReader
> DataGrid1.DataBind()
>
> End Sub
>
Eric Wise Guest
-
Yan-Hong Huang[MSFT] #3
Re: DDL values with DataReader and stored procedures
Hello Rob,
I have read the code that you paste. It seems that you populate companyID and name in ddlCompany drop down list. Then
populate ddlLocation drop down list according to the selected value in ddlCompany.
In the search button onclick handler, you ran a SP according to values from drop down list.
However, I am quite clear on your questions? Could you please explain more on what you want to implement, what the
problem is so that we could provide more information to you?
Thanks very much.
Best regards,
Yanhong Huang
Microsoft Online Partner Support
Get Secure! - [url]www.microsoft.com/security[/url]
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
!Content-Class: urn:content-classes:message
!From: "Rob Wire" <sts@hotmail.com>
!Sender: "Rob Wire" <sts@hotmail.com>
!References: <8e2e01c35b64$9c7a8c00$a001280a@phx.gbl> <#e5ogy2WDHA.3924@tk2msftngp13.phx.gbl>
!Subject: Re: DDL values with DataReader and stored procedures
!Date: Wed, 6 Aug 2003 12:29:31 -0700
!Lines: 122
!Message-ID: <070a01c35c51$0f20f3b0$a101280a@phx.gbl>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!Thread-Index: AcNcUQ8g52Xt2LxCT8+b0l82kNicsQ==
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:165489
!NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!How could I apply the below to a wildcard int primary key
!id field? i.e. to avoid getting:
!
!Syntax error converting the varchar value '%' to a column
!of data type int
!
!>-----Original Message-----
!>After you bind your dropdownlist and close the datareader
!just do an
!>items.insert "Select All" at position 0. Next line would
!be to set
!>items(0).value to % or whatever character you want.
!>
!>(Note sometimes I do "Choose One" as my position 0 with a
!value of empty
!>string "" so I can use a required field validator. Same
!concept)
!>
!>Hope this helps.
!>
!>"Rob Wire" <STS@hotmail.com> wrote in message
!>news:8e2e01c35b64$9c7a8c00$a001280a@phx.gbl...
!>> For the code below, how could I add an item in the drop
!>> down lists for both company and location to be an "All"
!>> selection that would send to the stored proc.
!>> spRptAttachments a value of "%" so that it would bring
!>> back all attachments at all companies or all locations
!at
!>> a company? Thank you, Rob.
!>>
!>> Private Sub Page_Load(ByVal sender As System.Object,
!>> ByVal e As System.EventArgs) Handles MyBase.Load
!>> If Not IsPostBack Then
!>> Dim cmd As System.Data.SqlClient.SqlCommand
!>> cmd = New System.Data.SqlClient.SqlCommand
!>> ("Web_CompanyList", Me.SqlConnection1)
!>> cmd.CommandType =
!CommandType.StoredProcedure
!>> Me.SqlConnection1.Open()
!>> Dim myDataReader As
!>> System.Data.Sqlclient.SqlDataReader = cmd.ExecuteReader
!>> (CommandBehavior.CloseConnection)
!>> ddlCompany.DataSource = myDataReader
!>> ddlCompany.DataValueField = "CompanyID"
!>> ddlCompany.DataTextField = "CompanyName"
!>> ddlCompany.DataBind()
!>> ddlCompany_SelectedIndexChanged(Nothing,
!>> Nothing)
!>> End If
!>> End Sub
!>>
!>> Private Sub ddlCompany_SelectedIndexChanged(ByVal
!>> sender As System.Object, ByVal e As System.EventArgs)
!>> Handles ddlCompany.SelectedIndexChanged
!>> Dim param As System.Data.SqlClient.SqlParameter
!>> Dim cmd As System.Data.SqlClient.SqlCommand
!>> Dim intCompanyID As Integer
!>> cmd = New System.Data.SqlClient.SqlCommand
!>> ("WEB_GetLocationFromCompanyID", Me.SqlConnection1)
!>> cmd.CommandType = CommandType.StoredProcedure
!>> param = cmd.Parameters.Add(New
!>> System.Data.SqlClient.SqlParameter("@CompanyID",
!>> SqlDbType.Int))
!>> param.Direction = ParameterDirection.Input
!>> ' ********Selected Value of Option List*******
!>> param.Value = ddlCompany.Items
!>> (ddlCompany.SelectedIndex).Value
!>> Me.SqlConnection1.Open()
!>> Dim myDataReader As
!>> System.Data.Sqlclient.SqlDataReader = cmd.ExecuteReader
!>> (CommandBehavior.CloseConnection)
!>> ddlLocation.DataSource = myDataReader
!>> ddlLocation.DataValueField = "CompanyLocationID"
!>> ddlLocation.DataTextField = "CoLo"
!>> ddlLocation.DataBind()
!>> End Sub
!>>
!>> Private Sub btnSearch_Click(ByVal sender As
!>> System.Object, ByVal e As System.EventArgs) Handles
!>> btnSearch.Click
!>> Dim prmDateFrom As
!>> System.Data.SqlClient.SqlParameter
!>> Dim prmCoID As
!System.Data.SqlClient.SqlParameter
!>> Dim prmColo As
!System.Data.SqlClient.SqlParameter
!>> Dim cmd As System.Data.SqlClient.SqlCommand
!>> Dim intCompanyID As Integer
!>> cmd = New System.Data.SqlClient.SqlCommand
!>> ("spRptAttachments", Me.SqlConnection1)
!>> cmd.CommandType = CommandType.StoredProcedure
!>> prmDateFrom = cmd.Parameters.Add(New
!>> System.Data.SqlClient.SqlParameter("@DateFrom",
!>> SqlDbType.DateTime))
!>> prmCoID = cmd.Parameters.Add(New
!>> System.Data.SqlClient.SqlParameter("@CompanyID",
!>> SqlDbType.Int))
!>> prmColo = cmd.Parameters.Add(New
!>> System.Data.SqlClient.SqlParameter("@CompanyLocati onID",
!>> SqlDbType.Int))
!>> prmDateFrom.Direction = ParameterDirection.Input
!>> prmCoID.Direction = ParameterDirection.Input
!>> prmColo.Direction = ParameterDirection.Input
!>> ' ********Selected Value of Option List*******
!>> prmDateFrom.Value = tbDateFrom.Text
!>> prmCoID.Value = ddlCompany.Items
!>> (ddlCompany.SelectedIndex).Value
!>> prmColo.Value = ddlLocation.Items
!>> (ddlLocation.SelectedIndex).Value
!>> Me.SqlConnection1.Open()
!>> Dim myDataReader As
!>> System.Data.Sqlclient.SqlDataReader = cmd.ExecuteReader
!>> (CommandBehavior.CloseConnection)
!>> DataGrid1.DataSource = myDataReader
!>> DataGrid1.DataBind()
!>>
!>> End Sub
!>>
!>
!>
!>.
!>
!
Yan-Hong Huang[MSFT] Guest
-
Rob Wire #4
Re: DDL values with DataReader and stored procedures
What I would like to do is have the ddl have a fake record
in the list that would send to the stored procedure a wild
card like '%' that would work with the int value of the
primary key field in the table that the drop down is
displaying, hence to return all rows no matter what the id
is if that is selected.
populate companyID and name in ddlCompany drop down list.>-----Original Message-----
>Hello Rob,
>
>I have read the code that you paste. It seems that you
Thenselected value in ddlCompany.>populate ddlLocation drop down list according to theaccording to values from drop down list.>
>In the search button onclick handler, you ran a SPplease explain more on what you want to implement, what>
>However, I am quite clear on your questions? Could you
theyou?>problem is so that we could provide more information toconfers no rights.>
>Thanks very much.
>
>Best regards,
>Yanhong Huang
>Microsoft Online Partner Support
>
>Get Secure! - [url]www.microsoft.com/security[/url]
>This posting is provided "AS IS" with no warranties, and<#e5ogy2WDHA.3924@tk2msftngp13.phx.gbl>>
>--------------------
>!Content-Class: urn:content-classes:message
>!From: "Rob Wire" <sts@hotmail.com>
>!Sender: "Rob Wire" <sts@hotmail.com>
>!References: <8e2e01c35b64$9c7a8c00$a001280a@phx.gbl>procedures>!Subject: Re: DDL values with DataReader and storedmicrosoft.public.dotnet.framework.aspnet:165489>!Date: Wed, 6 Aug 2003 12:29:31 -0700
>!Lines: 122
>!Message-ID: <070a01c35c51$0f20f3b0$a101280a@phx.gbl>
>!MIME-Version: 1.0
>!Content-Type: text/plain;
>! charset="iso-8859-1"
>!Content-Transfer-Encoding: 7bit
>!X-Newsreader: Microsoft CDO for Windows 2000
>!Thread-Index: AcNcUQ8g52Xt2LxCT8+b0l82kNicsQ==
>!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
>!Newsgroups: microsoft.public.dotnet.framework.aspnet
>!Path: cpmsftngxa06.phx.gbl
>!Xref: cpmsftngxa06.phx.gblkey>!NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
>!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>!
>!How could I apply the below to a wildcard int primarycolumn>!id field? i.e. to avoid getting:
>!
>!Syntax error converting the varchar value '%' to adatareader>!of data type int
>!
>!>-----Original Message-----
>!>After you bind your dropdownlist and close thewould>!just do an
>!>items.insert "Select All" at position 0. Next linea>!be to set
>!>items(0).value to % or whatever character you want.
>!>
>!>(Note sometimes I do "Choose One" as my position 0 withSame>!value of empty
>!>string "" so I can use a required field validator.drop>!concept)
>!>
>!>Hope this helps.
>!>
>!>"Rob Wire" <STS@hotmail.com> wrote in message
>!>news:8e2e01c35b64$9c7a8c00$a001280a@phx.gbl.. .
>!>> For the code below, how could I add an item in thean "All">!>> down lists for both company and location to belocations>!>> selection that would send to the stored proc.
>!>> spRptAttachments a value of "%" so that it would bring
>!>> back all attachments at all companies or allSystem.Object,>!at
>!>> a company? Thank you, Rob.
>!>>
>!>> Private Sub Page_Load(ByVal sender AsSystem.Data.SqlClient.SqlCommand>!>> ByVal e As System.EventArgs) Handles MyBase.Load
>!>> If Not IsPostBack Then
>!>> Dim cmd Ascmd.ExecuteReader>!>> cmd = New System.Data.SqlClient.SqlCommand
>!>> ("Web_CompanyList", Me.SqlConnection1)
>!>> cmd.CommandType =
>!CommandType.StoredProcedure
>!>> Me.SqlConnection1.Open()
>!>> Dim myDataReader As
>!>> System.Data.Sqlclient.SqlDataReader =System.Data.SqlClient.SqlParameter>!>> (CommandBehavior.CloseConnection)
>!>> ddlCompany.DataSource = myDataReader
>!>> ddlCompany.DataValueField = "CompanyID"
>!>> ddlCompany.DataTextField = "CompanyName"
>!>> ddlCompany.DataBind()
>!>> ddlCompany_SelectedIndexChanged(Nothing,
>!>> Nothing)
>!>> End If
>!>> End Sub
>!>>
>!>> Private Sub ddlCompany_SelectedIndexChanged(ByVal
>!>> sender As System.Object, ByVal e As System.EventArgs)
>!>> Handles ddlCompany.SelectedIndexChanged
>!>> Dim param Ascmd.ExecuteReader>!>> Dim cmd As System.Data.SqlClient.SqlCommand
>!>> Dim intCompanyID As Integer
>!>> cmd = New System.Data.SqlClient.SqlCommand
>!>> ("WEB_GetLocationFromCompanyID", Me.SqlConnection1)
>!>> cmd.CommandType = CommandType.StoredProcedure
>!>> param = cmd.Parameters.Add(New
>!>> System.Data.SqlClient.SqlParameter("@CompanyID",
>!>> SqlDbType.Int))
>!>> param.Direction = ParameterDirection.Input
>!>> ' ********Selected Value of Option List*******
>!>> param.Value = ddlCompany.Items
>!>> (ddlCompany.SelectedIndex).Value
>!>> Me.SqlConnection1.Open()
>!>> Dim myDataReader As
>!>> System.Data.Sqlclient.SqlDataReader == "CompanyLocationID">!>> (CommandBehavior.CloseConnection)
>!>> ddlLocation.DataSource = myDataReader
>!>> ddlLocation.DataValueField("@CompanyLocationID",>!>> ddlLocation.DataTextField = "CoLo"
>!>> ddlLocation.DataBind()
>!>> End Sub
>!>>
>!>> Private Sub btnSearch_Click(ByVal sender As
>!>> System.Object, ByVal e As System.EventArgs) Handles
>!>> btnSearch.Click
>!>> Dim prmDateFrom As
>!>> System.Data.SqlClient.SqlParameter
>!>> Dim prmCoID As
>!System.Data.SqlClient.SqlParameter
>!>> Dim prmColo As
>!System.Data.SqlClient.SqlParameter
>!>> Dim cmd As System.Data.SqlClient.SqlCommand
>!>> Dim intCompanyID As Integer
>!>> cmd = New System.Data.SqlClient.SqlCommand
>!>> ("spRptAttachments", Me.SqlConnection1)
>!>> cmd.CommandType = CommandType.StoredProcedure
>!>> prmDateFrom = cmd.Parameters.Add(New
>!>> System.Data.SqlClient.SqlParameter("@DateFrom",
>!>> SqlDbType.DateTime))
>!>> prmCoID = cmd.Parameters.Add(New
>!>> System.Data.SqlClient.SqlParameter("@CompanyID",
>!>> SqlDbType.Int))
>!>> prmColo = cmd.Parameters.Add(New
>!>> System.Data.SqlClient.SqlParameterParameterDirection.Input>!>> SqlDbType.Int))
>!>> prmDateFrom.Direction =cmd.ExecuteReader>!>> prmCoID.Direction = ParameterDirection.Input
>!>> prmColo.Direction = ParameterDirection.Input
>!>> ' ********Selected Value of Option List*******
>!>> prmDateFrom.Value = tbDateFrom.Text
>!>> prmCoID.Value = ddlCompany.Items
>!>> (ddlCompany.SelectedIndex).Value
>!>> prmColo.Value = ddlLocation.Items
>!>> (ddlLocation.SelectedIndex).Value
>!>> Me.SqlConnection1.Open()
>!>> Dim myDataReader As
>!>> System.Data.Sqlclient.SqlDataReader =>!>> (CommandBehavior.CloseConnection)
>!>> DataGrid1.DataSource = myDataReader
>!>> DataGrid1.DataBind()
>!>>
>!>> End Sub
>!>>
>!>
>!>
>!>.
>!>
>!
>
>
>.
>Rob Wire Guest
-
Yan-Hong Huang[MSFT] #5
Re: DDL values with DataReader and stored procedures
Hello Rob,
Sorry for the late response. I am not quite familar with SQL statements. So I am not sure of how to transfer a value like % for a
int value type. What I knew is that we could only use %, * in string type values.
My suggestion is to implement it in stored procedure level. For an example, when stored procedure received one specific
value, it will return all the rows no matter what ID is selected.
Please let me know if you have any concerns on it. Thanks.
Best regards,
Yanhong Huang
Microsoft Online Partner Support
Get Secure! - [url]www.microsoft.com/security[/url]
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
!Content-Class: urn:content-classes:message
!From: "Rob Wire" <sts@hotmail.com>
!Sender: "Rob Wire" <sts@hotmail.com>
!References: <8e2e01c35b64$9c7a8c00$a001280a@phx.gbl> <#e5ogy2WDHA.3924@tk2msftngp13.phx.gbl>
<070a01c35c51$0f20f3b0$a101280a@phx.gbl> <mqllFiLXDHA.1536@cpmsftngxa06.phx.gbl>
!Subject: Re: DDL values with DataReader and stored procedures
!Date: Fri, 8 Aug 2003 12:39:42 -0700
!Lines: 205
!Message-ID: <010501c35de4$d028b040$a601280a@phx.gbl>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcNd5NAmk8VGjaZQT1K+C0BMkc2Vuw==
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:166257
!NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!What I would like to do is have the ddl have a fake record
!in the list that would send to the stored procedure a wild
!card like '%' that would work with the int value of the
!primary key field in the table that the drop down is
!displaying, hence to return all rows no matter what the id
!is if that is selected.
!
!>-----Original Message-----
!>Hello Rob,
!>
!>I have read the code that you paste. It seems that you
!populate companyID and name in ddlCompany drop down list.
!Then
!>populate ddlLocation drop down list according to the
!selected value in ddlCompany.
!>
!>In the search button onclick handler, you ran a SP
!according to values from drop down list.
!>
!>However, I am quite clear on your questions? Could you
!please explain more on what you want to implement, what
!the
!>problem is so that we could provide more information to
!you?
!>
!>Thanks very much.
!>
!>Best regards,
!>Yanhong Huang
!>Microsoft Online Partner Support
!>
!>Get Secure! - [url]www.microsoft.com/security[/url]
!>This posting is provided "AS IS" with no warranties, and
!confers no rights.
!>
!>--------------------
!>!Content-Class: urn:content-classes:message
!>!From: "Rob Wire" <sts@hotmail.com>
!>!Sender: "Rob Wire" <sts@hotmail.com>
!>!References: <8e2e01c35b64$9c7a8c00$a001280a@phx.gbl>
!<#e5ogy2WDHA.3924@tk2msftngp13.phx.gbl>
!>!Subject: Re: DDL values with DataReader and stored
!procedures
!>!Date: Wed, 6 Aug 2003 12:29:31 -0700
!>!Lines: 122
!>!Message-ID: <070a01c35c51$0f20f3b0$a101280a@phx.gbl>
!>!MIME-Version: 1.0
!>!Content-Type: text/plain;
!>! charset="iso-8859-1"
!>!Content-Transfer-Encoding: 7bit
!>!X-Newsreader: Microsoft CDO for Windows 2000
!>!Thread-Index: AcNcUQ8g52Xt2LxCT8+b0l82kNicsQ==
!>!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!>!Newsgroups: microsoft.public.dotnet.framework.aspnet
!>!Path: cpmsftngxa06.phx.gbl
!>!Xref: cpmsftngxa06.phx.gbl
!microsoft.public.dotnet.framework.aspnet:165489
!>!NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
!>!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!>!
!>!How could I apply the below to a wildcard int primary
!key
!>!id field? i.e. to avoid getting:
!>!
!>!Syntax error converting the varchar value '%' to a
!column
!>!of data type int
!>!
!>!>-----Original Message-----
!>!>After you bind your dropdownlist and close the
!datareader
!>!just do an
!>!>items.insert "Select All" at position 0. Next line
!would
!>!be to set
!>!>items(0).value to % or whatever character you want.
!>!>
!>!>(Note sometimes I do "Choose One" as my position 0 with
!a
!>!value of empty
!>!>string "" so I can use a required field validator.
!Same
!>!concept)
!>!>
!>!>Hope this helps.
!>!>
!>!>"Rob Wire" <STS@hotmail.com> wrote in message
!>!>news:8e2e01c35b64$9c7a8c00$a001280a@phx.gbl.. .
!>!>> For the code below, how could I add an item in the
!drop
!>!>> down lists for both company and location to be
!an "All"
!>!>> selection that would send to the stored proc.
!>!>> spRptAttachments a value of "%" so that it would bring
!>!>> back all attachments at all companies or all
!locations
!>!at
!>!>> a company? Thank you, Rob.
!>!>>
!>!>> Private Sub Page_Load(ByVal sender As
!System.Object,
!>!>> ByVal e As System.EventArgs) Handles MyBase.Load
!>!>> If Not IsPostBack Then
!>!>> Dim cmd As
!System.Data.SqlClient.SqlCommand
!>!>> cmd = New System.Data.SqlClient.SqlCommand
!>!>> ("Web_CompanyList", Me.SqlConnection1)
!>!>> cmd.CommandType =
!>!CommandType.StoredProcedure
!>!>> Me.SqlConnection1.Open()
!>!>> Dim myDataReader As
!>!>> System.Data.Sqlclient.SqlDataReader =
!cmd.ExecuteReader
!>!>> (CommandBehavior.CloseConnection)
!>!>> ddlCompany.DataSource = myDataReader
!>!>> ddlCompany.DataValueField = "CompanyID"
!>!>> ddlCompany.DataTextField = "CompanyName"
!>!>> ddlCompany.DataBind()
!>!>> ddlCompany_SelectedIndexChanged(Nothing,
!>!>> Nothing)
!>!>> End If
!>!>> End Sub
!>!>>
!>!>> Private Sub ddlCompany_SelectedIndexChanged(ByVal
!>!>> sender As System.Object, ByVal e As System.EventArgs)
!>!>> Handles ddlCompany.SelectedIndexChanged
!>!>> Dim param As
!System.Data.SqlClient.SqlParameter
!>!>> Dim cmd As System.Data.SqlClient.SqlCommand
!>!>> Dim intCompanyID As Integer
!>!>> cmd = New System.Data.SqlClient.SqlCommand
!>!>> ("WEB_GetLocationFromCompanyID", Me.SqlConnection1)
!>!>> cmd.CommandType = CommandType.StoredProcedure
!>!>> param = cmd.Parameters.Add(New
!>!>> System.Data.SqlClient.SqlParameter("@CompanyID",
!>!>> SqlDbType.Int))
!>!>> param.Direction = ParameterDirection.Input
!>!>> ' ********Selected Value of Option List*******
!>!>> param.Value = ddlCompany.Items
!>!>> (ddlCompany.SelectedIndex).Value
!>!>> Me.SqlConnection1.Open()
!>!>> Dim myDataReader As
!>!>> System.Data.Sqlclient.SqlDataReader =
!cmd.ExecuteReader
!>!>> (CommandBehavior.CloseConnection)
!>!>> ddlLocation.DataSource = myDataReader
!>!>> ddlLocation.DataValueField
!= "CompanyLocationID"
!>!>> ddlLocation.DataTextField = "CoLo"
!>!>> ddlLocation.DataBind()
!>!>> End Sub
!>!>>
!>!>> Private Sub btnSearch_Click(ByVal sender As
!>!>> System.Object, ByVal e As System.EventArgs) Handles
!>!>> btnSearch.Click
!>!>> Dim prmDateFrom As
!>!>> System.Data.SqlClient.SqlParameter
!>!>> Dim prmCoID As
!>!System.Data.SqlClient.SqlParameter
!>!>> Dim prmColo As
!>!System.Data.SqlClient.SqlParameter
!>!>> Dim cmd As System.Data.SqlClient.SqlCommand
!>!>> Dim intCompanyID As Integer
!>!>> cmd = New System.Data.SqlClient.SqlCommand
!>!>> ("spRptAttachments", Me.SqlConnection1)
!>!>> cmd.CommandType = CommandType.StoredProcedure
!>!>> prmDateFrom = cmd.Parameters.Add(New
!>!>> System.Data.SqlClient.SqlParameter("@DateFrom",
!>!>> SqlDbType.DateTime))
!>!>> prmCoID = cmd.Parameters.Add(New
!>!>> System.Data.SqlClient.SqlParameter("@CompanyID",
!>!>> SqlDbType.Int))
!>!>> prmColo = cmd.Parameters.Add(New
!>!>> System.Data.SqlClient.SqlParameter
!("@CompanyLocationID",
!>!>> SqlDbType.Int))
!>!>> prmDateFrom.Direction =
!ParameterDirection.Input
!>!>> prmCoID.Direction = ParameterDirection.Input
!>!>> prmColo.Direction = ParameterDirection.Input
!>!>> ' ********Selected Value of Option List*******
!>!>> prmDateFrom.Value = tbDateFrom.Text
!>!>> prmCoID.Value = ddlCompany.Items
!>!>> (ddlCompany.SelectedIndex).Value
!>!>> prmColo.Value = ddlLocation.Items
!>!>> (ddlLocation.SelectedIndex).Value
!>!>> Me.SqlConnection1.Open()
!>!>> Dim myDataReader As
!>!>> System.Data.Sqlclient.SqlDataReader =
!cmd.ExecuteReader
!>!>> (CommandBehavior.CloseConnection)
!>!>> DataGrid1.DataSource = myDataReader
!>!>> DataGrid1.DataBind()
!>!>>
!>!>> End Sub
!>!>>
!>!>
!>!>
!>!>.
!>!>
!>!
!>
!>
!>.
!>
!
Yan-Hong Huang[MSFT] Guest



Reply With Quote

