Click here to Skip to main content
15,921,203 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
actual problem is value from text field is not transferring via insert query..can you solve this problem,i tried several times



ASP.NET
<%@ Page Title="" Language="C#" MasterPageFile="~/AdminMasterPage.master" AutoEventWireup="true" CodeFile="Add_Department_Admin.aspx.cs" Inherits="Add_Department_Admin" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .auto-style1 {
            width: 50%;
        }
    </style>
    <script  runat="server">
        private void InsertDEPARTMENT(object source, EventArgs e)
        {
            
             
  SqlDataSource2.Insert();
}
</script>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

   <h1>Add Department</h1>
    <table class="auto-style1">
        <tr>
            <td>Department</td>
            <td>
                <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="DEPARTMENT_NAME" DataValueField="DEPARTMENT_NAME">
                
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cresignsysConnectionString %>" SelectCommand="SELECT [DEPARTMENT_NAME] FROM [MCET_Department_Lookup]">
            </td>
        </tr>
        <tr>
            <td>Add Department:</td>
            <td>
                <asp:TextBox ID="TextBox1" runat="server" >

               
            </td>
        </tr>
        <tr>
            <td> </td>
            <td>
                
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:cresignsysConnectionString %>" DeleteCommand="DELETE FROM [MCET_Department_Lookup] WHERE [DEPARTMENT_ID] = @DEPARTMENT_ID" InsertCommand="INSERT INTO [MCET_Department_Lookup] ([DEPARTMENT_NAME]) VALUES (@DEPARTMENT_NAME)" SelectCommand="SELECT * FROM [MCET_Department_Lookup]" UpdateCommand="UPDATE [MCET_Department_Lookup] SET [DEPARTMENT_NAME] = @DEPARTMENT_NAME WHERE [DEPARTMENT_ID] = @DEPARTMENT_ID">
                    <deleteparameters>
                        <asp:Parameter Name="DEPARTMENT_ID" Type="Int64" />
                    </deleteparameters>
                    <insertparameters>
                       
                        <asp:FormParameter Name="DEPARTMENT_NAME" FormField="TextBox1" />
                    </insertparameters>
                    <updateparameters>
                        <asp:Parameter Name="DEPARTMENT_NAME" Type="String" />
                        <asp:Parameter Name="DEPARTMENT_ID" Type="Int64" />
                    </updateparameters>
                
                <asp:Button ID="Button1" runat="server" OnClick="InsertDEPARTMENT" Text="Button"  />
            </td>
        </tr>
    </table>
Posted
Updated 4-Aug-13 5:08am
v3
Comments
Reza Alipour Fard 4-Aug-13 0:53am    
Is your field in database null able?
What is your error or message or result?
abey e mathews 4-Aug-13 2:31am    
no errror but ,insert a new field with out any values...

i need the value in the testfiled to be inserted into database

abey e mathews 4-Aug-13 11:07am    
actual problem is value from text field is not trasfering via insert query..can you solve this proble,i tryed several times
CyberSaint 18-Jul-17 13:39pm    
check postback set type in insert parameter and comment the error... if no error then it will be postback set the if(ispostback!=null)

1 solution

Did you debug and see what is the actually value within InsertDepartment function?

I guess, submit button triggers the postback and you don't have the selected department anymore.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900