inserting data into database after selected indexchanged in dropdownlist

Mar 5 2011 1:22 AM
hi Guys ,Plz help me out 
i m havin the following code



<body>
    <form id="form1" runat="server">
    <div>
    <div>
        &nbsp;Have Pan Card:
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Width="316px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            
             <asp:ListItem>-----select----- </asp:ListItem>
            
            <asp:ListItem>yes</asp:ListItem>
            
            <asp:ListItem>no</asp:ListItem>
             
        </asp:DropDownList><br />
        &nbsp;</div>
    <div id="div1" runat="server">Enter Ist Choice &nbsp; &nbsp; &nbsp; &nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div>
         
            
    </div>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    </form>
</body>





and the code behind is here

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.OleDb;

public partial class demo : System.Web.UI.Page
{
    string pan, panno;
    OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["adbudhconnection"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        div1.Visible = false;
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        con.Open();
        OleDbCommand cmd = new OleDbCommand("insert into demo(pan,panno)values(@pan,@panno)", con);
        cmd.Parameters.AddWithValue("@pan", pan);
        cmd.Parameters.AddWithValue("@panno", panno);
        cmd.ExecuteNonQuery();
        con.Close();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedItem.Text == "yes")
        {
            div1.Visible = true;
           pan = DropDownList1.SelectedItem.Text;
            panno = TextBox1.Text;
        
        }
         else if (DropDownList1.SelectedItem.Text == "no")

        {
            
           pan = DropDownList1.SelectedItem.Text;
           panno = "n/a";
        
        
      
        }
         

    }

















}
this gives the error that
Parameter @pan has no default value




plz help its urgent



Answers (9)