IT Community - Software Programming, Web Development and Technical Support

ASP.NET Data Controls

This is a discussion on ASP.NET Data Controls within the ASP and ASP.NET Programming forums, part of the Web Development category; hi, I am getting an error :\Users\tmarie\Documents\MSDN\test\secure_members\ OrderSearch.aspx(26) : error BC30451: Name 'CustomerID' is ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #61  
Old 08-27-2007, 06:58 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 245
H2o is on a distinguished road
Question Re: ASP.NET Data Controls

hi,
I am getting an error
:\Users\tmarie\Documents\MSDN\test\secure_members\ OrderSearch.aspx(26) : error BC30451: Name 'CustomerID' is not declared.

SqlDataSource1.SelectCommand = "SELECT [ORDERID], [STATUS], [CUSTOMERID], [CUSTOMER_PO] FROM [test.csv] WHERE CUSTOMERID = " & CustomerID()
~~~~~~~~~~
C:\Users\tmarie\Documents\MSDN\test\secure_members \OrderSearch.aspx(27) : error BC30455: Argument not specified for parameter 'arguments' of 'Public Function Select(arguments As System.Web.UI.DataSourceSelectArguments) As System.Collections.IEnumerable'.

SqlDataSource1.Select()
~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\tmarie\Documents\MSDN\test\secure_members \OrderSearch.aspx(35) : error BC30455: Argument not specified for parameter 'arguments' of 'Public Function Select(arguments As System.Web.UI.DataSourceSelectArguments) As System.Collections.IEnumerable'.

SqlDataSource1.Select()
~~~~~~~~~~~~~~~~~~~~~~~
I thought that i declared 'CustomerID at the top.
and where in the Page_Load event do i put the if post back?
code i have right now.
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" %>
<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
Session("CustomerID") = Nothing

If User.Identity.IsAuthenticated Then
If User.IsInRole("admin") Then
If Request("CustomerID") IsNot Nothing Then
Session("CustomerID") = Request("CustomerID")
End If
Else
Session("CustomerID") = User.Identity.Name
End If
End If
'SqlDataSource1.SelectCommand = "SELECT [ORDERID], [STATUS], [CUSTOMERID], [CUSTOMER_PO] FROM [test.csv] WHERE CUSTOMERID = " & CustomerID()
'SqlDataSource1.Select()
'GridView1.DataBind()
End If


If Not IsPostBack Then
SqlDataSource1.SelectCommand = "SELECT [ORDERID], [STATUS], [CUSTOMERID], [CUSTOMER_PO] FROM [test.csv] WHERE CUSTOMERID = " & CustomerID()
SqlDataSource1.Select()
GridView1.DataBind()
End If

End Sub

Protected Sub Search_Click(ByVal sender As Object, ByVal e As System.EventArgs)SqlDataSource1.SelectCommand = "SELECT * FROM [test.csv] WHERE " & DropDownList1.SelectedItem.Text & " = " & txtSearch.Text
SqlDataSource1.Select()
GridView1.DataBind()
End Sub

</script>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" SkinID="KylieSkin"
EmptyDataText="There are no data records to display." AllowPaging="True" AllowSorting="True"
PageSize="20">
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT [ORDERID], [STATUS], [CUSTOMERID], [CUSTOMER_PO] FROM [test.csv] WHERE ([CUSTOMERID] = ?)" />
<selectparameters>
<asp:SessionParameter Name="CUSTOMERID" SessionField="CUSTOMERID" Type="String" />
</selectparameters>
</asp:SqlDataSource> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
<aspropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="Customer_PO">Customer P.O.</asp:ListItem>
</aspropDownList>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="search" /><br />
</asp:Content>
__________________
H2O

Without us, no one can survive..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #62  
Old 08-27-2007, 06:59 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 347
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

hi,

If you look at my code in the previous post, I have take removed the SelectParameters and using SelectCommand itself to create my query. That is the one of the reason why you are getting the error.
Secondly in the Page_Load event in the Not IsPostback section, I have remarked that you have to check your CustomerID there. So I was assuming that you would have a variable called CustomerID and was using this variable in the SelectCommand. In your code, you are using it as a function called CustomerID() and not as a variable.
If Not IsPostBack Then
' Do your checking for CustomerID
dim CustomerID as Integer = Cint(Session("CustomerID"))
SqlDataSource1.SelectCommand = "SELECT [ORDERID], [STATUS], [CUSTOMERID], [CUSTOMER_PO] FROM [test.csv] WHERE CUSTOMERID = " &
CustomerID
SqlDataSource1.Select()
GridView1.DataBind()
End If
In the above code, I haven't done any error checking.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #63  
Old 08-27-2007, 07:16 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 881
kingmaker is on a distinguished road
Send a message via MSN to kingmaker
Question Re: ASP.NET Data Controls

hi guys,

I have my ODS in SP, I've problem to choose the column in the Table (the part which I bold the font below), it is syntax error.
Any comment? Thanks for helps..
SELECT
SampleToolItem .*,
Creators.UserName ItemCreatorDisplayName

FROM
SampleToolItem
INNER JOIN aspnet_users AS Creators ON Creators.UserId = SampleToolItem.ItemCreatorId
Where
SampleToolItem.@ddl = @tb
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #64  
Old 08-27-2007, 07:17 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 347
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

hi,

SampleToolItem.@ddl = @tb
@ddl is a variable and you cannot (as far as I know) reference a column name like this.
SampleToolItem.ItemID = @ItemID
In the above SampleToolItem is your tablename, ItemID is your column(or field) in your table and @ItemID is the variable that you are passing.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #65  
Old 08-27-2007, 07:19 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 881
kingmaker is on a distinguished road
Send a message via MSN to kingmaker
Thumbs up Re: ASP.NET Data Controls

hi venkat,

Ya,that is the problem. Actually I have a search function for GV which consist of a Dropdownlist(search by) and a Textbox.
So, I can't assign the static column name in the SP but have to depend on the selection by user.
Maybe there are alternative solution for this? Or how can I reference to the column name selected by user?(the @ddl)
Thanks a lot!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #66  
Old 08-27-2007, 07:31 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 347
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

hi kingmaker,

If you are setting the SelectCommand then you can do this.
SqlDataSource1.SelectCommand = "SELECT * FROM [test.csv] WHERE " & ColumnName & " = " & searchCriteria
If you are using Stored procedure and columnname and searchcriteria as parameters, then you have to do
DECLARE @SQLQUERY VARCHAR(1000)

SET @SQLQUERY = N'SELECT * FROM TABLE1 WHERE ' + QUOTENAME(@COLUMNNAME) + ' = ' + @SearchCriteria

EXEC (@SQLQUERY)
In the above QuoteName is used to thwart Sql injection.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #67  
Old 08-27-2007, 07:35 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 881
kingmaker is on a distinguished road
Send a message via MSN to kingmaker
Thumbs up Re: ASP.NET Data Controls

hi,

When I do like that, it force me to key in the textbox's text exactly same as the ddl's item value.
Example:
<aspropDownList ID="ddlSearch" runat="server">
<asp:ListItem Value="ModelName">Model Name</asp:ListItem>
<asp:ListItem Value="ModelNo">Model No</asp:ListItem>
</aspropDownList>
if I key in "name1", the error is:
Invalid column name 'name1
if I key in "ModelName", display all the GV rows
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #68  
Old 08-27-2007, 07:36 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 881
kingmaker is on a distinguished road
Send a message via MSN to kingmaker
Thumbs up Re: ASP.NET Data Controls

hey guys,

I solve it by:

WHERE
CASE
WHEN @ddl='ModelName' THEN ModelName
WHEN @ddl='ModelNo' THEN ModelNo
END
=@tb
Thanks for help
Wish to know other method if u have other ideas,
thanks
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #69  
Old 08-28-2007, 03:28 AM
H2o H2o is offline
D-Web Analyst
 
Join Date: Jul 2007
Posts: 245
H2o is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

Hi guys,

I am trying send an email when a row in my gridview has been updated based on a checkbox in grideview = true.
I Keep getting the error "object reference not set to an insatnce of an object"
I am assuming that this is because the code isn't finding the checkbox.
I have editing enable for the gridview.....What is the name of the checkbox ( in edit mode ) in the grid view.
My aspx page contains <asp:CheckBoxField DataField="ApprovedBy_HR"
What should my code behind use to refernce this..
I tried the following
Dim VarHRApproved As CheckBox = CType(GridView1.FindControl("ApprovedBy_HRCheckBox "), CheckBox)
If VarHRApproved.Checked = True Then
'create the mail message
Thx in advance,
__________________
H2O

Without us, no one can survive..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #70  
Old 08-28-2007, 03:36 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 347
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

hey H2o,

Since we don't know the name of the control, you simply pull the control out of the specific cell's control collection. For example, if your CheckBoxField was the first column of your GridView, then you'd retrieve the CheckBox reference like so:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow gvr = e.Row;

if (gvr.RowType == DataControlRowType.DataRow)
{
CheckBox chk = gvr.Cells[0].Controls[0] as CheckBox;
}
}
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
silverlight controls for .net stevejhon ASP and ASP.NET Programming 1 03-25-2009 10:31 AM
silverlight controls for .net stevejhon ASP and ASP.NET Programming 0 03-23-2009 01:55 AM
How can we Dynamically create web controls Kirubhananth ASP and ASP.NET Programming 3 03-14-2008 09:00 PM
WebParts controls S.Vinothkumar ASP and ASP.NET Programming 5 11-16-2007 02:06 AM
Asp.net controls not supported by Ajax? Gopisoft ASP and ASP.NET Programming 0 07-16-2007 11:22 PM


All times are GMT -7. The time now is 11:26 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0