Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 20th, 2007, 07:45 AM
Registered User
 
Join Date: Jan 2007
Location: , , Belgium.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting data using a dropdownlist

Hi,

i've been browsing through an extensive array of topics these last few hours but i can't seem to find the solution for my problem.

I've build a little app in which our projects and relating data should be organized (using visual Web Developer and Sql Server Express). I used scripts to import data into the DB and i am able to view that data. By example; I have a Projects-page where i can view, using a dropdownlist, projects from one customer and then drill down to see the hours worked for that project or the tasks that need to be done. So far so good.

Now i've build a page to add new projects to the database. I included 3 dropdownlists with which i can select the type, category and client for the project. When i enter the remaining data and press "insert" i get an error:

Cannot insert the value NULL into column 'CLIENT', table 'TrAction.dbo.PROJECT'; column does not allow nulls. INSERT fails.
The statement has been terminated.

Since the designated field is NOT-NULL a value is required. Apparently the SEQ for the Client doesn't get loaded into the new record, allthough i think it should do so since it is the value-field for my dropdownlist. Am i missing something in the InsertItemTemplate?

As many of you will have guessed by now, I'm rather new to ASP and .Net :-D

Greetz, and many thanks for now.

Johan

P.S. Here's the full code for the page:

[code]

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AddProject.aspx.vb" Inherits="AddProject" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Add Project</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FormView ID="FormView1" runat="server" DataKeyNames="SEQ" DataSourceID="SqlDataSource_AddProject" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical">
            <InsertItemTemplate>
                PROJECT_TYPE:
                <asp:DropDownList ID="InsertCategoryTypeDropDownList"
                        SelectedValue='<%# Bind("SEQ") %>'
                        DataSourceID="SqlDataSource_GetProjectType"
                        DataTextField="Title"
                        DataValueField="SEQ"
                        RunAt="Server" /><br />
                PROJECT_CATEGORY:
                <asp:DropDownList ID="InsertProjectCategoryDropDownList"
                        SelectedValue='<%# Bind("SEQ") %>'
                        DataSourceID="SqlDataSource_GetProjectCategory"
                        DataTextField="Title"
                        DataValueField="SEQ"
                        RunAt="Server" /><br />
                CLIENT:
                <asp:DropDownList ID="InsertClientDropDownList"
                        SelectedValue='<%# Bind("SEQ") %>'
                        DataSourceID="SqlDataSource_GetClient"
                        DataTextField="Name"
                        DataValueField="SEQ"
                        RunAt="Server" /><br />
                TITLE:
                <asp:TextBox ID="TITLETextBox" runat="server" Text='<%# Bind("TITLE") %>'>
                </asp:TextBox><br />
                DESCRIPTION:
                <asp:TextBox ID="DESCRIPTIONTextBox" runat="server" Text='<%# Bind("DESCRIPTION") %>'>
                </asp:TextBox><br />
                LOC_TOWN:
                <asp:TextBox ID="LOC_TOWNTextBox" runat="server" Text='<%# Bind("LOC_TOWN") %>'>
                </asp:TextBox><br />
                LOC_STREET:
                <asp:TextBox ID="LOC_STREETTextBox" runat="server" Text='<%# Bind("LOC_STREET") %>'>
                </asp:TextBox><br />
                LOC_NUMBER:
                <asp:TextBox ID="LOC_NUMBERTextBox" runat="server" Text='<%# Bind("LOC_NUMBER") %>'>
                </asp:TextBox><br />
                LOC_CADASTER:
                <asp:TextBox ID="LOC_CADASTERTextBox" runat="server" Text='<%# Bind("LOC_CADASTER") %>'>
                </asp:TextBox><br />
                ACTIVE:
                <asp:CheckBox ID="ACTIVECheckBox" runat="server" Checked='<%# Bind("ACTIVE") %>' /><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>
                CODE:
                <asp:Label ID="CODELabel" runat="server" Text='<%# Bind("CODE") %>'></asp:Label><br />
                PROJECT_TYPE:
                <asp:Label ID="PROJECT_TYPELabel" runat="server" Text='<%# Bind("PROJECT_TYPE") %>'>
                </asp:Label><br />
                PROJECT_CATEGORY:
                <asp:Label ID="PROJECT_CATEGORYLabel" runat="server" Text='<%# Bind("PROJECT_CATEGORY") %>'>
                </asp:Label><br />
                CLIENT:
                <asp:Label ID="CLIENTLabel" runat="server" Text='<%# Bind("CLIENT") %>'></asp:Label><br />
                TITLE:
                <asp:Label ID="TITLELabel" runat="server" Text='<%# Bind("TITLE") %>'></asp:Label><br />
                DESCRIPTION:
                <asp:Label ID="DESCRIPTIONLabel" runat="server" Text='<%# Bind("DESCRIPTION") %>'>
                </asp:Label><br />
                LOC_TOWN:
                <asp:Label ID="LOC_TOWNLabel" runat="server" Text='<%# Bind("LOC_TOWN") %>'></asp:Label><br />
                LOC_STREET:
                <asp:Label ID="LOC_STREETLabel" runat="server" Text='<%# Bind("LOC_STREET") %>'>
                </asp:Label><br />
                LOC_NUMBER:
                <asp:Label ID="LOC_NUMBERLabel" runat="server" Text='<%# Bind("LOC_NUMBER") %>'>
                </asp:Label><br />
                LOC_CADASTER:
                <asp:Label ID="LOC_CADASTERLabel" runat="server" Text='<%# Bind("LOC_CADASTER") %>'>
                </asp:Label><br />
                ACTIVE:
                <asp:CheckBox ID="ACTIVECheckBox" runat="server" Checked='<%# Bind("ACTIVE") %>'
                    Enabled="false" /><br />
                <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                    Text="New">
                </asp:LinkButton>
            </ItemTemplate>
            <FooterStyle BackColor="#CCCC99" />
            <EditRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#F7F7DE" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
        </asp:FormView>
        <asp:SqlDataSource ID="SqlDataSource_AddProject" runat="server" ConnectionString="<%$ ConnectionStrings:TrActionConnectionString %>"
            DeleteCommand="DELETE FROM [PROJECT] WHERE [SEQ] = @SEQ" InsertCommand="DECLARE @NewDat datetime#13;#10;DECLARE @NewUser int#13;#10;DECLARE @NewCode numeric(4)#13;#10;#13;#10;SET @NewDat = (SELECT getdate())#13;#10;SET @NewUser = (SELECT SEQ FROM TEAM WHERE NAME = 'Admin')#13;#10;SET @NewCode = (SELECT max(code)+1 from project)#13;#10;#13;#10;INSERT INTO [PROJECT] ([CREDAT], [CREUSR], [CODE], [PROJECT_TYPE], [PROJECT_CATEGORY], [CLIENT], [TITLE], [DESCRIPTION], [LOC_TOWN], [LOC_STREET], [LOC_NUMBER], [LOC_CADASTER], [ACTIVE]) VALUES (@NewDat, @NewUser, @NewCode, @PROJECT_TYPE, @PROJECT_CATEGORY, @CLIENT, @TITLE, @DESCRIPTION, @LOC_TOWN, @LOC_STREET, @LOC_NUMBER, @LOC_CADASTER, @ACTIVE)"
            SelectCommand="SELECT * FROM [PROJECT] ORDER BY [CODE] DESC" UpdateCommand="UPDATE [PROJECT] SET [CREDAT] = @CREDAT, [CREUSR] = @CREUSR, [UPDDAT] = @UPDDAT, [UPDUSR] = @UPDUSR, [CODE] = @CODE, [PROJECT_TYPE] = @PROJECT_TYPE, [PROJECT_CATEGORY] = @PROJECT_CATEGORY, [CLIENT] = @CLIENT, [TITLE] = @TITLE, [DESCRIPTION] = @DESCRIPTION, [LOC_TOWN] = @LOC_TOWN, [LOC_STREET] = @LOC_STREET, [LOC_NUMBER] = @LOC_NUMBER, [LOC_CADASTER] = @LOC_CADASTER, [ACTIVE] = @ACTIVE WHERE [SEQ] = @SEQ">
            <DeleteParameters>
                <asp:Parameter Name="SEQ" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="CREDAT" Type="DateTime" />
                <asp:Parameter Name="CREUSR" Type="String" />
                <asp:Parameter Name="UPDDAT" Type="DateTime" />
                <asp:Parameter Name="UPDUSR" Type="String" />
                <asp:Parameter Name="CODE" Type="Decimal" />
                <asp:Parameter Name="PROJECT_TYPE" Type="Int32" ConvertEmptyStringToNull="false" />
                <asp:Parameter Name="PROJECT_CATEGORY" Type="Int32" ConvertEmptyStringToNull="false" />
                <asp:Parameter Name="CLIENT" Type="Int32" ConvertEmptyStringToNull="false" />
                <asp:Parameter Name="TITLE" Type="String" />
                <asp:Parameter Name="DESCRIPTION" Type="String" />
                <asp:Parameter Name="LOC_TOWN" Type="String" />
                <asp:Parameter Name="LOC_STREET" Type="String" />
                <asp:Parameter Name="LOC_NUMBER" Type="String" />
                <asp:Parameter Name="LOC_CADASTER" Type="String" />
                <asp:Parameter Name="ACTIVE" Type="Boolean" />
                <asp:Parameter Name="SEQ" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="CREDAT" Type="DateTime" />
                <asp:Parameter Name="CREUSR" Type="String" />
                <asp:Parameter Name="UPDDAT" Type="DateTime" />
                <asp:Parameter Name="UPDUSR" Type="String" />
                <asp:Parameter Name="CODE" Type="Decimal" />
                <asp:Parameter Name="PROJECT_TYPE" Type="Int32" />
                <asp:Parameter Name="PROJECT_CATEGORY" Type="Int32" />
                <asp:Parameter Name="CLIENT" Type="Int32" />
                <asp:Parameter Name="TITLE" Type="String" />
                <asp:Parameter Name="DESCRIPTION" Type="String" />
                <asp:Parameter Name="LOC_TOWN" Type="String" />
                <asp:Parameter Name="LOC_STREET" Type="String" />
                <asp:Parameter Name="LOC_NUMBER" Type="String" />
                <asp:Parameter Name="LOC_CADASTER" Type="String" />
                <asp:Parameter Name="ACTIVE" Type="Boolean" />
            </InsertParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource_GetClient" runat="server" ConnectionString="<%$ ConnectionStrings:TrActionConnectionString %>"
            SelectCommand="SELECT [SEQ], [NAME] FROM [CLIENT] ORDER BY [NAME]"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource_GetProjectCategory" runat="server" ConnectionString="<%$ ConnectionStrings:TrActionConnectionString %>"
            SelectCommand="SELECT [SEQ], [TITLE] FROM [PROJECT_CATEGORY] ORDER BY [CODE]"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource_GetProjectType" runat="server" ConnectionString="<%$ ConnectionStrings:TrActionConnectionString %>"
            SelectCommand="SELECT [SEQ], [TITLE] FROM [PROJECT_TYPE] ORDER BY
Code:
"></asp:SqlDataSource>
Code:
        &nbsp;&nbsp;

    </div>
    </form>
</body>
</html>




Similar Threads
Thread Thread Starter Forum Replies Last Post
inserting data stevens ADO.NET 0 May 13th, 2008 07:49 AM
Data inserting twice nuttylife2 ASP.NET 2.0 Professional 8 August 22nd, 2006 11:01 AM
Inserting data when data already exsist desireemm SQL Language 0 January 16th, 2006 11:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.