2
Answers

want insert button coding.

manish berwal

manish berwal

11y
1k
1
hey friends i am new on asp.net language. Could anyone help me for the insert button coding for below code .
Please reply soon ....I am waiting for response.     thanx in advance.......


reply here or mail me at [email protected]........

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void mylist(object sender, EventArgs e)
    {

        DropDownList7.Items.Insert(0, new ListItem("- Select -", ""));
    }
    protected void mylist2(object sender, EventArgs e)
    {

        DropDownList2.Items.Insert(0, new ListItem("- Select -", ""));
    }
    protected void mylist3(object sender, EventArgs e)
    {

        DropDownList3.Items.Insert(0, new ListItem("- Select -", ""));
    }
    protected void mylist4(object sender, EventArgs e)
    {

        DropDownList4.Items.Insert(0, new ListItem("- Select -", ""));
    }
    protected void mylist5(object sender, EventArgs e)
    {

        DropDownList5.Items.Insert(0, new ListItem("- Select -", ""));
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList7.SelectedIndex == 0)
        {
            string message = "Enter Block Name Name";
            ClientScript.RegisterStartupScript(this.GetType(), "My title", "alert('" + message + "');", true);
            return;
        }
        if (DropDownList4.SelectedIndex==0)
        {
            string message1 = "Enter Department Name";
            ClientScript.RegisterStartupScript(this.GetType(), "My title", "alert('" + message1 + "');", true);
            return;
        }
        if (DropDownList5.SelectedIndex == 0)
        {
            string message1 = "Enter GP/Owner Name";
            ClientScript.RegisterStartupScript(this.GetType(), "My title", "alert('" + message1 + "');", true);
            return;
        }
        if (DropDownList1.SelectedIndex == 0)
        {
            string message1 = "Enter Village Name";
            ClientScript.RegisterStartupScript(this.GetType(), "My title", "alert('" + message1 + "');", true);
            return;
        }
        if (DropDownList2.SelectedIndex == 0)
        {
            string message1 = "Bank Name";
            ClientScript.RegisterStartupScript(this.GetType(), "My title", "alert('" + message1 + "');", true);
            return;
        }
        if (DropDownList3.SelectedIndex == 0)
        {
            string message1 = "Enter Branch Name";
            ClientScript.RegisterStartupScript(this.GetType(), "My title", "alert('" + message1 + "');", true);
            return;
        }


        if (TextBox7.Text == "")
        {
            string message1 = "Enter Amount of FD";
            ClientScript.RegisterStartupScript(this.GetType(), "My title", "alert('" + message1 + "');", true);
            return;
        }
        if (TextBox8.Text == "")
        {
            string message1 = "Enter Start date of FD";
            ClientScript.RegisterStartupScript(this.GetType(), "My title", "alert('" + message1 + "');", true);
            return;
        }
        if (TextBox9.Text == "")
        {
            string message1 = "Enter Period of FD";
            ClientScript.RegisterStartupScript(this.GetType(), "My title", "alert('" + message1 + "');", true);
            return;
        }
        if (TextBox10.Text == "")
        {
            string message1 = "Enter Rate of Interest on FD";
            ClientScript.RegisterStartupScript(this.GetType(), "My title", "alert('" + message1 + "');", true);
            return;
        }

        SqlConnection con1;
        SqlCommand com1;
        SqlDataReader dr1;
        con1 = new SqlConnection("data source=NIC-70809787BA9;initial catalog=fd;user id=sa;password=nic");       
        con1.Open();
       
       com1 =new SqlCommand("INSERT INTO main VALUES(@Sr_no, @block_name, @dept_name, @gp/owner_name, @vill_name, @fd_amount, @fd_startdate, @fd_period, @roi, @bank_name, @branch, @remarks)",con1  );
       com1.CommandType =CommandType.Text;

       com1.Parameters.Add("@block_name", SqlDbType.NVarChar, 90).Value = DropDownList7.SelectedValue;
       com1.Parameters.Add("@dept_name", SqlDbType.NVarChar, 90).Value = DropDownList4.SelectedValue;
       com1.Parameters.Add("@gp/owner_name", SqlDbType.NVarChar, 90).Value = DropDownList5.SelectedValue;
       com1.Parameters.Add("@vill_name", SqlDbType.NChar, 10).Value = DropDownList1.SelectedValue;
       com1.Parameters.Add("@fd_amount", SqlDbType.BigInt).Value = TextBox7.Text;
       com1.Parameters.Add("@fd_startdate", SqlDbType.DateTime).Value = TextBox8.Text;
       com1.Parameters.Add("@fd_period", SqlDbType.NChar, 10).Value = TextBox8.Text;
       com1.Parameters.Add("@bank_name", SqlDbType.NVarChar, 90).Value = DropDownList2.SelectedValue;
       com1.Parameters.Add("@branch", SqlDbType.NVarChar, 90).Value = DropDownList3.SelectedValue;
       com1.Parameters.Add("@remarks", SqlDbType.NVarChar, 240).Value = TextBox6.Text;
    com1.ExecuteNonQuery();
}

  
    protected void  Button2_Click(object sender, EventArgs e)
{
    Response.Redirect("entry.aspx");
}
    protected void TextBox8_TextChanged(object sender, EventArgs e)
    {

     

    }
}
   


Answers (2)