How can form validation be done?

Hi Experts,

I have the following script:

How can the two text boxes be validated upon clicking on "Insert"?

I want to detect if there is any value entered for "CostCategoryTextBox" and display a msg box if there is not. Also I want to use the value of "CostCategoryTextBox" to query if there is a record that already exists with the same value. How can this be done? I am new to ASP.net and using Visual Web Developer.

Thanks
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Logistics_Budget_ManagerConnectionString1 %>"
        DeleteCommand="DELETE FROM [Cost Category] WHERE [CostCategoryID] = @CostCategoryID"
        InsertCommand="INSERT INTO [Cost Category] ([CostCategory], [Description]) VALUES (@CostCategory, @Description)"
        ProviderName="<%$ ConnectionStrings:Logistics_Budget_ManagerConnectionString1.ProviderName %>"
        SelectCommand="SELECT [CostCategoryID], [CostCategory], [Description] FROM [Cost Category]"
        UpdateCommand="UPDATE [Cost Category] SET [CostCategory] = @CostCategory, [Description] = @Description WHERE [CostCategoryID] = @CostCategoryID">
        <DeleteParameters>
            <asp:Parameter Name="CostCategoryID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="CostCategory" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="CostCategory" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="CostCategoryID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:FormView ID="FormView1" runat="server" OnPageIndexChanging="FormView1_PageIndexChanging1" DefaultMode="Insert" DataKeyNames="CostCategoryID" DataSourceID="SqlDataSource1" Width="454px">
        <InsertItemTemplate>
            <span style="font-size: 10pt; font-family: Arial"><strong>
                <table style="width: 434px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid;">
                    <tr>
                        <td style="width: 134px; height: 26px;" valign="top">
                            Cost Category:</td>
                        <td style="width: 100px; height: 26px;">
                        <asp:TextBox ID="CostCategoryTextBox" runat="server" Text='<%# Bind("CostCategory") %>' Width="305px"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 134px; height: 58px" valign="top">
                            Description:
                        </td>
                        <td style="width: 100px; height: 58px">
                            <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' Height="54px" Width="305px"></asp:TextBox>
                        </td>
                    </tr>
                    </span>
                     <tr>
                        <td colspan="2">
                            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                            Text="Insert" Font-Names="Arial"></asp:LinkButton>
                            &nbsp;&nbsp;
                            
                            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                            Text="Cancel" Font-Names="Arial"></asp:LinkButton>
                        </td>
                    </tr>                   
            </TBODY></TABLE></STRONG>
       </InsertItemTemplate>
        <ItemTemplate>
            CostCategoryID:
            <asp:Label ID="CostCategoryIDLabel" runat="server" Text='<%# Eval("CostCategoryID") %>'></asp:Label><br />
            CostCategory:
            <asp:Label ID="CostCategoryLabel" runat="server" Text='<%# Bind("CostCategory") %>'></asp:Label><br />
            Description:
            <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Bind("Description") %>'></asp:Label><br />
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                Text="Edit"></asp:LinkButton>
            <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                Text="Delete"></asp:LinkButton>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                Text="New"></asp:LinkButton>
        </ItemTemplate>
        <EditItemTemplate>
            CostCategoryID:
            <asp:Label ID="CostCategoryIDLabel1" runat="server" Text='<%# Eval("CostCategoryID") %>'>
            </asp:Label><br />
            CostCategory:
            <asp:TextBox ID="CostCategoryTextBox" runat="server" Text='<%# Bind("CostCategory") %>'>
            </asp:TextBox><br />
            Description:
            <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'>
            </asp:TextBox><br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update">
            </asp:LinkButton>
            &nbsp;
            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel">
            </asp:LinkButton>
        </EditItemTemplate>
    </asp:FormView>

Open in new window

LVL 1
indyngAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tony_angelopoulosCommented:
This is easy to do and it's built into asp.net, have a look at the below, incuding the examples link at the bottom of the page:

http://www.w3schools.com/ASPNET/control_reqfieldvalidator.asp
0
indyngAuthor Commented:
tony_angelopoulos:

I got that one but how do I use the text box value in a query to determine if the value exists in a table?

Thanks

0
tony_angelopoulosCommented:
It will require ado.net inside a function in your code-behind.  I can work on that tonight or tomorrow for you (if someone doesn't beat me to it!)
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

tony_angelopoulosCommented:
You will need a new Custom validator like so in addition to your required validator:

<asp:CustomValidator ID="cvName" Runat="server"  OnServerValidate="CustomValidator1_ServerValidate" ErrorMessage="Record Already Exists" ControlToValidate="CostCategoryTextBox"></asp:CustomValidator>

AND:

Something like the following:  (forgive me if there are a few syntax errors.  This is in VB, can be done in C# as well, place in your code behind)

 
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
        Dim profile As String = profileId.Text
        Dim conn As New SqlClient.SqlConnection("your connection string here")
 
        Dim da As New SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
        da.SelectCommand.Parameters.AddWithValue("@CostCategory", CostCategoryTextBox.Value)
        Dim ds As New DataSet()
        da.Fill(ds)
	args.IsValid = (ds.Tables(0).Rows.Count = 0)
	da.Dispose()
End Sub

Open in new window

0
indyngAuthor Commented:
tony_angelopoulos:

Where do I place this script?

Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
        Dim profile As String = profileId.Text
        Dim conn As New SqlClient.SqlConnection("your connection string here")
 
        Dim da As New SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
        da.SelectCommand.Parameters.AddWithValue("@CostCategory", CostCategoryTextBox.Value)
        Dim ds As New DataSet()
        da.Fill(ds)
      args.IsValid = (ds.Tables(0).Rows.Count = 0)
      da.Dispose()
End Sub


THANKS
0
tony_angelopoulosCommented:
I would place it in the code behind for the web page, or in a <script language="vb.net"> </script> on the page itself.  Check that I'm checking the right thing in my sql query:  you are looking for duplicates in the cost category field, correct?
0
indyngAuthor Commented:
I got this error:

Line 1:  
Line 2:  
Line 3:  <script language=vbscript>
Line 4:  Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
Line 5:          Dim profile As String = profileId.Text
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
 
<script language=vbscript>
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
        Dim profile As String = profileId.Text
        Dim conn As New SqlClient.SqlConnection("your connection string here")
 
        Dim da As New SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
        da.SelectCommand.Parameters.AddWithValue("@CostCategory", CostCategoryTextBox.Value)
        Dim ds As New DataSet()
        da.Fill(ds)
	args.IsValid = (ds.Tables(0).Rows.Count = 0)
	da.Dispose()
End Sub
</script>
 
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <br />
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="CostCategoryID" DataSourceID="SqlDataSource1"
        DefaultMode="Insert" Width="632px">
        <EditItemTemplate>
            CostCategoryID:
            <asp:Label ID="CostCategoryIDLabel1" runat="server" Text='<%# Eval("CostCategoryID") %>'>
            </asp:Label><br />
            CostCategory:
            <asp:TextBox ID="CostCategoryTextBox" runat="server" Text='<%# Bind("CostCategory") %>'>
            </asp:TextBox><br />
            Description:
            <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'>
            </asp:TextBox><br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update">
            </asp:LinkButton>
            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel">
            </asp:LinkButton>
        </EditItemTemplate>
        <InsertItemTemplate>
            <strong>Cost Category:</strong>
            <asp:TextBox ID="CostCategoryTextBox" runat="server" Text='<%# Bind("CostCategory") %>'></asp:TextBox>
            <strong>Description: </strong>
            <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'
                Width="194px"></asp:TextBox><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="CostCategoryTextBox" ErrorMessage="The Cost Category field is required "></asp:RequiredFieldValidator><br />
            <asp:CustomValidator ID="cvName" Runat="server"  OnServerValidate="CustomValidator1_ServerValidate" ErrorMessage="Record Already Exists" ControlToValidate="CostCategoryTextBox"></asp:CustomValidator>
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert"></asp:LinkButton>
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel"></asp:LinkButton>
        </InsertItemTemplate>
        
 
 
        <ItemTemplate>
            CostCategoryID:
            <asp:Label ID="CostCategoryIDLabel" runat="server" Text='<%# Eval("CostCategoryID") %>'></asp:Label><br />
            CostCategory:
            <asp:Label ID="CostCategoryLabel" runat="server" Text='<%# Bind("CostCategory") %>'></asp:Label><br />
            Description:
            <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Bind("Description") %>'></asp:Label><br />
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                Text="Edit"></asp:LinkButton>
            <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                Text="Delete"></asp:LinkButton>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                Text="New"></asp:LinkButton>
        </ItemTemplate>
 
    </asp:FormView>
    <br />
 
    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
        CellPadding="4" DataKeyNames="CostCategoryID" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display."
        ForeColor="#333333" GridLines="None" Width="628px">
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <Columns>
            <asp:BoundField DataField="CostCategory" HeaderText="CostCategory" SortExpression="CostCategory" />
            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
        </Columns>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Logistics_Budget_ManagerConnectionString1 %>"
        DeleteCommand="DELETE FROM [Cost Category] WHERE [CostCategoryID] = @CostCategoryID"
        InsertCommand="INSERT INTO [Cost Category] ([CostCategory], [Description]) VALUES (@CostCategory, @Description)"
        ProviderName="<%$ ConnectionStrings:Logistics_Budget_ManagerConnectionString1.ProviderName %>"
        SelectCommand="SELECT [CostCategoryID], [CostCategory], [Description] FROM [Cost Category]"
        UpdateCommand="UPDATE [Cost Category] SET [CostCategory] = @CostCategory, [Description] = @Description WHERE [CostCategoryID] = @CostCategoryID">
        <DeleteParameters>
            <asp:Parameter Name="CostCategoryID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="CostCategory" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="CostCategory" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="CostCategoryID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
 
</asp:Content>

Open in new window

0
tony_angelopoulosCommented:
well, it's not vbscript, it's vb.net, but change the script line from:

<script language=vbscript>

to
<script runat="server">

and remove the line:
Dim profile As String = profileId.Text

I copied the code from an existing project and it does not belong...
we'll get there!
0
tony_angelopoulosCommented:
right under your page declaration you might need these two imports:

<%@ Import namespace=System.Data %>
<%@ Import namespace=System.Data.SqlClient %>
0
indyngAuthor Commented:
What is the syntax for the connection string?
Dim conn As New SqlClient.SqlConnection("your connection string here")

THANKS
0
tony_angelopoulosCommented:
put another import at the top under page declaration:
<%@ Import namespace=System.Web.Configuration %>

add:

Dim conString as String = WebConfigurationManager.ConnectionStrings("Logistics_Budget_ManagerConnectionString1").ToString()

then put:
Dim conn As New SqlClient.SqlConnection(conString)

0
indyngAuthor Commented:
Got this error:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'WebConfigurationManager' is not declared.

Source Error:

 

Line 6:  <script runat="server">
Line 7:      Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
Line 8:          Dim conString As String = WebConfigurationManager.ConnectionStrings("Logistics_Budget_ManagerConnectionString1").ToString()
Line 9:          Dim conn As New SqlClient.SqlConnection(conString)
Line 10:         Dim da As New SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
 

Source File: C:\Documents and Settings\RXNg\My Documents\Visual Studio 2005\WebSites\Logistics_Budget_Manager\ManageCostCategory.aspx    Line: 8

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Manage Cost Category" %>
 
<%@ Import namespace=System.Data %>
<%@ Import namespace=System.Web.Configuration %>
<%@ Import namespace=System.Data.SqlClient %>
<script runat="server">
    Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
        Dim conString As String = WebConfigurationManager.ConnectionStrings("Logistics_Budget_ManagerConnectionString1").ToString()
        Dim conn As New SqlClient.SqlConnection(conString)
        Dim da As New SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
        da.SelectCommand.Parameters.AddWithValue("@CostCategory", CostCategoryTextBox.Value)
        Dim ds As New DataSet()
        da.Fill(ds)
        args.IsValid = (ds.Tables(0).Rows.Count = 0)
        da.Dispose()
    End Sub
</script>
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <br/>
    &nbsp;<br />
 
    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
        CellPadding="4" DataKeyNames="CostCategoryID" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display."
        ForeColor="#333333" GridLines="None" Width="628px">
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <Columns>
            <asp:BoundField DataField="CostCategory" HeaderText="CostCategory" SortExpression="CostCategory" NullDisplayText="Please enter value" />
            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
        </Columns>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Logistics_Budget_ManagerConnectionString1 %>"
        DeleteCommand="DELETE FROM [Cost Category] WHERE [CostCategoryID] = @CostCategoryID"
        InsertCommand="INSERT INTO [Cost Category] ([CostCategory], [Description]) VALUES (@CostCategory, @Description)"
        ProviderName="<%$ ConnectionStrings:Logistics_Budget_ManagerConnectionString1.ProviderName %>"
        SelectCommand="SELECT [CostCategoryID], [CostCategory], [Description] FROM [Cost Category]"
        UpdateCommand="UPDATE [Cost Category] SET [CostCategory] = @CostCategory, [Description] = @Description WHERE [CostCategoryID] = @CostCategoryID">
        <DeleteParameters>
            <asp:Parameter Name="CostCategoryID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="CostCategory" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="CostCategory" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="CostCategoryID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <br />
    <asp:Panel ID="Panel1" runat="server" visible="true">
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="CostCategoryID" DataSourceID="SqlDataSource1" Width="632px">
        <EditItemTemplate>
            CostCategoryID:
            <asp:Label ID="CostCategoryIDLabel1" runat="server" Text='<%# Eval("CostCategoryID") %>'>
            </asp:Label><br />
            CostCategory:
            <asp:TextBox ID="CostCategoryTextBox" runat="server" Text='<%# Bind("CostCategory") %>'>
            </asp:TextBox><br />
            Description:
            <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'>
            </asp:TextBox><br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update">
            </asp:LinkButton>
            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel">
            </asp:LinkButton>
        </EditItemTemplate>
        <InsertItemTemplate>
            <strong>Cost Category:</strong>
            <asp:TextBox ID="CostCategoryTextBox" runat="server" Text='<%# Bind("CostCategory") %>'></asp:TextBox>
            <strong>Description: </strong>
            <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'
                Width="194px"></asp:TextBox><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="CostCategoryTextBox" SetFocusOnError="True" Display="Dynamic" ToolTip="Enter a Cost Category" ErrorMessage="The Cost Category field is required "></asp:RequiredFieldValidator><br />
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert"></asp:LinkButton>
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel"></asp:LinkButton>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                Text="New"></asp:LinkButton>
        </ItemTemplate>
 
    </asp:FormView>
    </asp:Panel>
 
</asp:Content>

Open in new window

0
tony_angelopoulosCommented:
lets try putting the namespaces in quotes like

<%@ Import namespace="System.Data" %>
0
indyngAuthor Commented:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30002: Type 'SqlClient.SqlConnection' is not defined.

Source Error:

 

Line 7:      Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
Line 8:          Dim conString As String = WebConfigurationManager.ConnectionStrings("Logistics_Budget_ManagerConnectionString1").ToString()
Line 9:          Dim conn As New SqlClient.SqlConnection(conString)
Line 10:         Dim da As New SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
Line 11:         da.SelectCommand.Parameters.AddWithValue("@CostCategory", CostCategoryTextBox.Value)
 

Source File: C:\Documents and Settings\RXNg\My Documents\Visual Studio 2005\WebSites\Logistics_Budget_Manager\ManageCostCategory.aspx    Line: 9

 

Line 6:  <script runat="server">
Line 7:      Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
Line 8:          Dim conString As String = WebConfigurationManager.ConnectionStrings("Logistics_Budget_ManagerConnectionString1").ToString()
Line 9:          Dim conn As New SqlClient.SqlConnection(conString)
Line 10:         Dim da As New SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
 

Source File: C:\Documents and Settings\RXNg\My Documents\Visual Studio 2005\WebSites\Logistics_Budget_Manager\ManageCostCategory.aspx    Line: 8

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Manage Cost Category" %>
 
<%@ Import namespace="System.Data%>
<%@ Import namespace="System.Web.Configuration"%>
<%@ Import namespace="System.Data.SqlClient"%>
<script runat="server">
    Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
        Dim conString As String = WebConfigurationManager.ConnectionStrings("Logistics_Budget_ManagerConnectionString1").ToString()
        Dim conn As New SqlClient.SqlConnection(conString)
        Dim da As New SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
        da.SelectCommand.Parameters.AddWithValue("@CostCategory", CostCategoryTextBox.Value)
        Dim ds As New DataSet()
        da.Fill(ds)
        args.IsValid = (ds.Tables(0).Rows.Count = 0)
        da.Dispose()
    End Sub
</script>
 
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <br/>
    &nbsp;<br />
 
    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
        CellPadding="4" DataKeyNames="CostCategoryID" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display."
        ForeColor="#333333" GridLines="None" Width="628px">
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <Columns>
           <asp:TemplateField HeaderText="CostCategory" SortExpression="CostCategory">                
              <ItemTemplate>
                     <%#Eval("CostCategory") %>
              </ItemTemplate>
 
              <EditItemTemplate>
              <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="CostCategoryTextBox" SetFocusOnError="True" Display="Dynamic" ToolTip="Enter a Cost Category" ErrorMessage="The Cost Category field is required " ValidationGroup="GridGroup" />
                      <asp:TextBox runat="server" ID="CostCategoryTextBox" Text='<%#Bind("CostCategory") %>' />
                      
              </EditItemTemplate>
            </asp:TemplateField> 
            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            
        
            
        </Columns>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Logistics_Budget_ManagerConnectionString1 %>"
        DeleteCommand="DELETE FROM [Cost Category] WHERE [CostCategoryID] = @CostCategoryID"
        InsertCommand="INSERT INTO [Cost Category] ([CostCategory], [Description]) VALUES (@CostCategory, @Description)"
        ProviderName="<%$ ConnectionStrings:Logistics_Budget_ManagerConnectionString1.ProviderName %>"
        SelectCommand="SELECT [CostCategoryID], [CostCategory], [Description] FROM [Cost Category]"
        UpdateCommand="UPDATE [Cost Category] SET [CostCategory] = @CostCategory, [Description] = @Description WHERE [CostCategoryID] = @CostCategoryID">
        <DeleteParameters>
            <asp:Parameter Name="CostCategoryID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="CostCategory" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="CostCategory" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="CostCategoryID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <br />
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="CostCategoryID" DataSourceID="SqlDataSource1" Width="632px">
        <EditItemTemplate>
            CostCategoryID:
            <asp:Label ID="CostCategoryIDLabel1" runat="server" Text='<%# Eval("CostCategoryID") %>'>
            </asp:Label><br />
            CostCategory:
            <asp:TextBox ID="CostCategoryTextBox" runat="server" Text='<%# Bind("CostCategory") %>'>
            </asp:TextBox><br />
            Description:
            <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'>
            </asp:TextBox><br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update">
            </asp:LinkButton>
            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel">
            </asp:LinkButton>
        </EditItemTemplate>
        <InsertItemTemplate>
            <strong>Cost Category:</strong>
            <asp:TextBox ID="CostCategoryTextBox" runat="server" Text='<%# Bind("CostCategory") %>' ValidationGroup="FormGroup"></asp:TextBox>
            <strong>Description: </strong>
            <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'
                Width="194px"></asp:TextBox><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="CostCategoryTextBox" SetFocusOnError="True" Display="Dynamic" ToolTip="Enter a Cost Category" ErrorMessage="The Cost Category field is required "></asp:RequiredFieldValidator><br />
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert"></asp:LinkButton>
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel"></asp:LinkButton>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                Text="New"></asp:LinkButton>
        </ItemTemplate>
 
    </asp:FormView>
    <br />
 
</asp:Content>

Open in new window

0
indyngAuthor Commented:
I get this error:

 

Line 16:         Dim conn As New Data.SqlClient.SqlConnection("Logistics_Budget_Manager_ConnectionString1")
Line 17:         Dim da As New Data.SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
Line 18:         da.SelectCommand.Parameters.AddWithValue("@CostCategory", CostCategoryTextBox.Value)
Line 19:         Dim ds As New Data.DataSet()
Line 20:         da.Fill(ds)
 

    Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
        'MsgBox("TEST")
        Dim conn As New Data.SqlClient.SqlConnection("Logistics_Budget_Manager_ConnectionString1")
        Dim da As New Data.SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
        da.SelectCommand.Parameters.AddWithValue("@CostCategory", CostCategoryTextBox.Value)
        Dim ds As New Data.DataSet()
        da.Fill(ds)
        args.IsValid = (ds.Tables(0).Rows.Count = 0)
        da.Dispose()
 
    End Sub

Open in new window

0
tony_angelopoulosCommented:
I appologize, my PC is down and I am trying to do this from a community PC (without studio, nonetheless)

Let's try prefacing the stuff below with System.  It's still having some trouble resolving namespaces.  I usually code in the codebehind (and that in C#), so bear with me...

Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
        'MsgBox("TEST")
        Dim conn As New System.Data.SqlClient.SqlConnection("Logistics_Budget_Manager_ConnectionString1")
        Dim da As New System.Data.SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
        da.SelectCommand.Parameters.AddWithValue("@CostCategory", CostCategoryTextBox.Value)
        Dim ds As New Data.DataSet()
        da.Fill(ds)
        args.IsValid = (ds.Tables(0).Rows.Count = 0)
        da.Dispose()
 
    End Sub
0
indyngAuthor Commented:
Tony:

I copied your script and now I have this error:

Format of the initialization string does not conform to specification starting at index 0.

which occured at:
        Dim conn As New System.Data.SqlClient.SqlConnection("Logistics_Budget_Manager_ConnectionString1")

I really appreciate you sticking with me and helping despite my ignorance with ASP.net

Thanks
0
indyngAuthor Commented:
I changed the SqlConnection to
Dim conn As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\RXNg\My Documents\Visual Studio 2005\WebSites\Logistics_Budget_Manager\App_Data\Logistics_Budget_Manager.mdf';Integrated Security=True;User Instance=True")

Now my code is this, but I am now getting the following error:

System.Data.SqlClient.SqlException was unhandled by user code
  Class=16
  ErrorCode=-2146232060
  LineNumber=1
  Message="The data types text and nvarchar are incompatible in the equal to operator."
  Number=402
  Procedure=""
  Server="\\.\pipe\AD62AABA-9C11-41\tsql\query"
  Source=".Net SqlClient Data Provider"
  State=1
  StackTrace:
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
       at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
       at System.Data.SqlClient.SqlDataReader.get_MetaData()
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
       at ASP.managecostcategory_aspx.CustomValidator1_ServerValidate(Object source, ServerValidateEventArgs args) in C:\Documents and Settings\RXNg\My Documents\Visual Studio 2005\WebSites\Logistics_Budget_Manager\ManageCostCategory.aspx:line 20
       at System.Web.UI.WebControls.CustomValidator.OnServerValidate(String value)
       at System.Web.UI.WebControls.CustomValidator.EvaluateIsValid()
       at System.Web.UI.WebControls.BaseValidator.Validate()
       at System.Web.UI.Page.Validate()
       at System.Web.UI.Page.Validate(String validationGroup)
       at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
        'MsgBox("TEST")
        Dim conn As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\RXNg\My Documents\Visual Studio 2005\WebSites\Logistics_Budget_Manager\App_Data\Logistics_Budget_Manager.mdf';Integrated Security=True;User Instance=True")
        Dim da As New System.Data.SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
        da.SelectCommand.Parameters.AddWithValue("@CostCategory", "Other")
        Dim ds As New Data.DataSet()
        da.Fill(ds)
        args.IsValid = (ds.Tables(0).Rows.Count = 0)
        da.Dispose()
        
    End Sub

Open in new window

0
indyngAuthor Commented:
Okay now I have this:

I had to use e.Values("CostCategory") so the value can be detected from the textbox in the formview. Now how do i use this value in a query to detect if value already exists in table?

Thanks

    Protected Sub CostCategoryFormView_ItemInserting(ByVal sender As Object, ByVal e As FormViewInsertEventArgs)
 
        Dim conn As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\RXNg\My Documents\Visual Studio 2005\WebSites\Logistics_Budget_Manager\App_Data\Logistics_Budget_Manager.mdf';Integrated Security=True;User Instance=True")
        Dim da As New System.Data.SqlClient.SqlDataAdapter("SELECT [CostCategoryID] FROM [Cost Category] WHERE [CostCategory] = @CostCategory", conn)
        MsgBox(e.Values("CostCategory"))
    End Sub

Open in new window

0
tony_angelopoulosCommented:
going this route you would need:
after Dim da line:
da.SelectCommand.Parameters.AddWithValue("@CostCategory", e.Values("CostCategory"))
da.Fill(ds)
if  ds.Tables(0).Rows.Count > 0 then
     ' exists, abort the insert and change a label control to display the message
     e.cancel = true
     somelabel.text = "Item Exists."
end if  

for more information see thread:
http://forums.asp.net/t/1116970.aspx
         


0
indyngAuthor Commented:
Tony,

I have this now but am getting this error:
The data types text and nvarchar are incompatible in the equal to operator.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: The data types text and nvarchar are incompatible in the equal to operator.

Source Error:


Line 17:        
Line 18:         da.SelectCommand.Parameters.AddWithValue("@CostCategory", e.Values("CostCategory"))
Line 19:         da.Fill(ds)
Line 20:         If ds.Tables(0).Rows.Count > 0 Then
Line 21:             ' exists, abort the insert and change a label control to display the message
 

Source File: C:\Documents and Settings\RXNg\My Documents\Visual Studio 2005\WebSites\Logistics_Budget_Manager\ManageCostCategory.aspx    Line: 19

THANKS
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Manage Cost Category" %>
 
<script runat="server">
 
    Protected Sub ShowAddNewForm(ByVal sender As Object, ByVal e As System.EventArgs)
        If CostCategoryFormView.Visible = True Then
            CostCategoryFormView.Visible = False
        Else
            CostCategoryFormView.Visible = True
        End If
    End Sub
    
    Protected Sub CostCategoryFormView_ItemInserting(ByVal sender As Object, ByVal e As FormViewInsertEventArgs)
        Dim ds As New Data.DataSet()
        Dim conn As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\RXNg\My Documents\Visual Studio 2005\WebSites\Logistics_Budget_Manager\App_Data\Logistics_Budget_Manager.mdf';Integrated Security=True;User Instance=True")
        Dim da As New System.Data.SqlClient.SqlDataAdapter("SELECT * FROM [Cost Category] WHERE [Cost Category].CostCategory=@CostCategory", conn)
        
        da.SelectCommand.Parameters.AddWithValue("@CostCategory", e.Values("CostCategory"))
        da.Fill(ds)
        If ds.Tables(0).Rows.Count > 0 Then
            ' exists, abort the insert and change a label control to display the message
            e.Cancel = True
            MsgBox("Item exists!")
        End If
 
    End Sub
    
</script>
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <br/>
    
    <asp:FormView ID="CostCategoryFormView" runat="server" DataKeyNames="CostCategoryID" DataSourceID="SqlDataSource1" Width="786px" Font-Bold="False" Font-Names="Arial" Font-Size="10pt"
    OnItemInserting="CostCategoryFormView_ItemInserting">
        <InsertItemTemplate>
            <strong>
                <table style="width: 540px">
                    <tr>
                        <td style="height: 26px; width: 106px;">
                            Cost Category:
                        </td>
                        <td style="width: 47px; height: 26px;">
            <asp:TextBox ID="CostCategoryTextBox" runat="server" Text='<%# Bind("CostCategory") %>' ValidationGroup="FormGroup" Width="307px"></asp:TextBox></td>
                        <td style="width: 100px; height: 26px;">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="CostCategoryTextBox" SetFocusOnError="True" Display="Dynamic" ToolTip="Enter a Cost Category" ErrorMessage="*Required Field" Width="113px" Font-Bold="False" Font-Italic="True"></asp:RequiredFieldValidator></td>
                    </tr>
                    <tr>
                        <td style="width: 106px" valign="top">
                            Description: 
                        </td>
                        <td style="width: 47px">
            <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'
                Width="306px" Height="48px"></asp:TextBox></td>
                        <td style="width: 100px">
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 106px">
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert" Font-Bold="False" Font-Size="10pt"></asp:LinkButton>&nbsp;
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel" Font-Bold="False" Font-Size="10pt"></asp:LinkButton></td>
                        <td style="width: 47px">
                        </td>
                        <td style="width: 100px">
                        </td>
                    </tr>
                </table>
            </strong>
        </InsertItemTemplate>
        <ItemTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                Text="Add New"></asp:LinkButton>
        </ItemTemplate>
 
    </asp:FormView>
    <br />
 
    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
        CellPadding="4" DataKeyNames="CostCategoryID" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display."
        ForeColor="#333333" GridLines="None" Width="788px" Font-Names="Arial" Font-Size="10pt">
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <Columns>
           <asp:TemplateField HeaderText="Cost Category" SortExpression="CostCategory">                
              <ItemTemplate>
                <%#Eval("CostCategory") %>
              </ItemTemplate>
 
              <EditItemTemplate>
                <asp:TextBox runat="server" ID="CostCategoryTextBox" Text='<%#Bind("CostCategory") %>' />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="CostCategoryTextBox" SetFocusOnError="True" Display="Dynamic" ToolTip="Enter a Cost Category" ErrorMessage="*Required Field" ValidationGroup="GridGroup" />
              </EditItemTemplate>
            </asp:TemplateField> 
 
            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
   
            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                        Text="Update" OnClick="ShowAddNewForm" ValidationGroup="GridGroup"></asp:LinkButton>
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                        Text="Cancel" OnClick="ShowAddNewForm"></asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                        Text="Edit" OnClick="ShowAddNewForm"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowDeleteButton="True"/>   
        </Columns>
        
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Logistics_Budget_ManagerConnectionString1 %>"
        DeleteCommand="DELETE FROM [Cost Category] WHERE [CostCategoryID] = @CostCategoryID"
        InsertCommand="INSERT INTO [Cost Category] ([CostCategory], [Description]) VALUES (@CostCategory, @Description)"
        ProviderName="<%$ ConnectionStrings:Logistics_Budget_ManagerConnectionString1.ProviderName %>"
        SelectCommand="SELECT [CostCategoryID], [CostCategory], [Description] FROM [Cost Category]"
        UpdateCommand="UPDATE [Cost Category] SET [CostCategory] = @CostCategory, [Description] = @Description WHERE [CostCategoryID] = @CostCategoryID">
        <DeleteParameters>
            <asp:Parameter Name="CostCategoryID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="CostCategory" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="CostCategory" Type="String" />
            <asp:Parameter Name="Description" Type="String" />
            <asp:Parameter Name="CostCategoryID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
 
</asp:Content>

Open in new window

0
tony_angelopoulosCommented:
is the costcategory column on your table a text datatype or nvarchar?  This is a common issue with database table columns that are of the text datatype.

see below for this known issue:

http://forums.asp.net/p/950661/1158004.aspx#1158004


You might need to change the datatype (on the table) to nvarchar(max) for the costcategory column (if it's a text type).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.