-
Sep 10th, 2007, 06:43 PM
#1
Thread Starter
Member
Using a Filter Expression in an SqlDataSource for an Integer Value
I have a gridview bound to a sqldatasource with a select command that selects from a table. When a user selects a row in that grid, my formview control should populate with that row's info. My formview is bound to another sqldatasource which has the same select command as the first sqldatasource but it has a filterexpression based on the value of a column from the selected row. The problem is that the column that I'm using the filterexpression on is an int32 (the column in the db is an identity seed) so as soon as I select the row from the gridview, I get the following error: "Cannot perform '=' operation on System.Int32 and System.String." Ok, I get that. It's looking for a string value and I'm giving it an Int32. So how do I fix this? I was able to capture the value on the GridView1_SelectedIndexChanged event (SqlDataSource2.filterexpression="c_entry='" & GridView1.SelectedRow.Cells(8).Text & "'". But I'm guessing this is a fairly common issue so there's got to be a way to get it to work without capturing the event and feeding it the value. So what's the secret?
-
Sep 11th, 2007, 07:07 PM
#2
Re: Using a Filter Expression in an SqlDataSource for an Integer Value
My formview is bound to another sqldatasource which has the same select command as the first sqldatasource but it has a filterexpression based on the value of a column from the selected row.
Are you specifying parameters for your sql command, or just appending a bunch of data?
Here's a simple example
vb Code:
'bad
sqlCommand.CommandText = "Select somedata from mytable where id = " & id
'good
sqlCommand.CommandText = "Select somedata from mytable where id = @id"
sqlCommand.Parameters.Add("@id", id)
-
Sep 13th, 2007, 10:27 AM
#3
Thread Starter
Member
Re: Using a Filter Expression in an SqlDataSource for an Integer Value
I'm using a sqldatasource control and it's properties are set to:
sqldatasource1.selectcommand="select * from mytable"
sqldatasource1.filterexpression="id='@id'"
I got this from a microsoft sample program. Is there a better way?
-
Sep 15th, 2007, 04:35 PM
#4
Re: Using a Filter Expression in an SqlDataSource for an Integer Value
My formview is bound to another sqldatasource which has the same select command as the first sqldatasource but it has a filterexpression based on the value of a column from the selected row.
Show your relevant ASPX/HTML code for this.
-
Sep 17th, 2007, 10:55 AM
#5
Thread Starter
Member
-
Sep 17th, 2007, 03:50 PM
#6
Re: Using a Filter Expression in an SqlDataSource for an Integer Value
Is the dropdownlist populated after the gridview is populated?
-
Sep 18th, 2007, 09:15 AM
#7
Thread Starter
Member
Re: Using a Filter Expression in an SqlDataSource for an Integer Value
No, the dropdown list is populated first. The user then chooses an item on the dropdown list and the gridview is populated. When the user selects a row on the gridview, it's supposed to populate the formview with that record.
-
Sep 23rd, 2014, 04:07 AM
#8
New Member
Re: Using a Filter Expression in an SqlDataSource for an Integer Value
Originally Posted by Pitbull
I have a gridview bound to a sqldatasource with a select command that selects from a table. When a user selects a row in that grid, my formview control should populate with that row's info. My formview is bound to another sqldatasource which has the same select command as the first sqldatasource but it has a filterexpression based on the value of a column from the selected row. The problem is that the column that I'm using the filterexpression on is an int32 (the column in the db is an identity seed) so as soon as I select the row from the gridview, I get the following error: "Cannot perform '=' operation on System.Int32 and System.String." Ok, I get that. It's looking for a string value and I'm giving it an Int32. So how do I fix this? I was able to capture the value on the GridView1_SelectedIndexChanged event (SqlDataSource2.filterexpression="c_entry='" & GridView1.SelectedRow.Cells(8).Text & "'". But I'm guessing this is a fairly common issue so there's got to be a way to get it to work without capturing the event and feeding it the value. So what's the secret?
Hi Pitbull, would you mind posting your solution for the filter expression issue here, cuz I really wanna know how this worked out. Thanks.
-
Sep 24th, 2014, 02:39 PM
#9
Re: Using a Filter Expression in an SqlDataSource for an Integer Value
This thread is seven years old, so he probably won't be tracking it. What have you got for code?
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Sep 24th, 2014, 10:02 PM
#10
New Member
Re: Using a Filter Expression in an SqlDataSource for an Integer Value
Just bumped into this page, and curious how this turned out..sorry I forgot to check the time, never meant for any thread resurrection.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|