Inserting dropdown list numeric value to oracle database

Last post 04-20-2007 8:18 AM by sthauttam. 6 replies.

Sort Posts:

  • Inserting dropdown list numeric value to oracle database

    04-19-2007, 12:14 PM
    • Loading...
    • sthauttam
    • Joined on 01-03-2007, 1:10 PM
    • Posts 75

    Hi Everybody!

    In dropdown list i have

    1. USA

    2. Japan

    3. UK

    Now, when i select on Japan, in the database say there is table name COUNTRY with column name  ID. How can i store the corresponding country value in the ID column? I mean I have to store 2  when i select Japan.

    I would appreciate your suggestion.

    Thanks!

    Uttam   

     

    Filed under: , ,
  • Re: Inserting dropdown list numeric value to oracle database

    04-19-2007, 12:36 PM
    Answer

    1) To get the value from the drop down list, use SELECTEDVALUE property

    2) Open the database and call executenonquery of the command object to store the value.

     

    Which step you  stucked on?

  • Re: Inserting dropdown list numeric value to oracle database

    04-19-2007, 12:40 PM
    Answer
    • Loading...
    • pixelsyndicate
    • Joined on 07-04-2003, 12:56 PM
    • W. MI transplant in N. TX
    • Posts 1,082

    One suggestion: generate your SQL for the insert based on the value of the dropdownlist:

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (((DropDownList)sender).SelectedIndex > 0)
            {
    
                string sql = "insert into Country (ID) Values ('" + ((DropDownList)sender).SelectedValue + "')";
             {
        }

     

    < asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" style="position: relative">
                < asp:ListItem Selected="True" Value="0">Select Value< /asp:ListItem>
                < asp:ListItem Value="1">USA< /asp:ListItem>
                < asp:ListItem Value="2">JAPAN< /asp:ListItem>
                < asp:ListItem Value="3">UK< /asp:ListItem>
                < asp:ListItem Value="4">NoWhere< /asp:ListItem>
            < /asp:DropDownList>
     There are safer and more complex ways to do it, but the basics include getting the SelectedValue from the DropDownList and doing an Insert statement to oracle.
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." ~ Douglas Adams

    http://pixelsyndicate.com/ps/
  • Re: Inserting dropdown list numeric value to oracle database

    04-19-2007, 2:20 PM
    Answer
    • Loading...
    • sthauttam
    • Joined on 01-03-2007, 1:10 PM
    • Posts 75

    Thanks! Smiling4ever

     When I inserted the selected value, it showed error message

    ORA-00984: column not allowed here

     

    protected void btnSearch_Click(object sender, EventArgs e)

    {

    // Label1.Text = ddMaterialLst.SelectedValue;

    string str = "Provider=\"OraOLEDB.Oracle.1\";User ID=owner;Password=pass;Data Source=world";

    OleDbConnection con = new OleDbConnection(str);

    OleDbCommand cmd = new OleDbCommand("INSERT into address1(no) values(num)",con);

     

  • Re: Inserting dropdown list numeric value to oracle database

    04-19-2007, 2:24 PM
    Answer
    • Loading...
    • sthauttam
    • Joined on 01-03-2007, 1:10 PM
    • Posts 75

    Wow! Excellent

     Thanks pixelsyndicate.

     thank you!

     

     

     

    pixelsyndicate:

    One suggestion: generate your SQL for the insert based on the value of the dropdownlist:

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (((DropDownList)sender).SelectedIndex > 0)
            {
    
                string sql = "insert into Country (ID) Values ('" + ((DropDownList)sender).SelectedValue + "')";
             {
        }

     

    < asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" style="position: relative">
                < asp:ListItem Selected="True" Value="0">Select Value< /asp:ListItem>
                < asp:ListItem Value="1">USA< /asp:ListItem>
                < asp:ListItem Value="2">JAPAN< /asp:ListItem>
                < asp:ListItem Value="3">UK< /asp:ListItem>
                < asp:ListItem Value="4">NoWhere< /asp:ListItem>
            < /asp:DropDownList>
     There are safer and more complex ways to do it, but the basics include getting the SelectedValue from the DropDownList and doing an Insert statement to oracle.
    Filed under: , ,
  • Re: Inserting dropdown list numeric value to oracle database

    04-20-2007, 5:48 AM
    Answer
    So you got to know how to do it or not yet?
  • Re: Inserting dropdown list numeric value to oracle database

    04-20-2007, 8:18 AM
    • Loading...
    • sthauttam
    • Joined on 01-03-2007, 1:10 PM
    • Posts 75

    Thanks! Smiling4ever

    I got it.

     Thanks!

    Filed under: ,
Page 1 of 1 (7 items)
Microsoft Communities
Page view counter