Click here to Skip to main content
15,914,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have one dropdownlist and one textbox whatever we select or enter it should be store into database..means if i select dropdownlist then selected value will store into database or if i enter value into textbox it sholud be store into database..at time we can use only one means dropdowlist or textbox for storing same value in same database field..
Posted
Updated 28-May-12 0:33am
v2

try like this
VB
If TextBox1.Text Is Nothing Then
            cmd = New SqlCommand("insert into sample   values('" + DropDownList1.SelectedItem.Text + "')")
        Else
            cmd = New SqlCommand("insert into sample   values('" + TextBox1.Text + "')")
        End If
cmd.ExecuteNonQuery ()
 
Share this answer
 
as for the logic part:

C#
if (TextBox1.Text.Trim() != string.Empty)
        {
            //The text box is not empty so let us use this value to push in DB
        }
        else
        {
            string valueToPush = DropDownList1.SelectedValue;
            //Now push this value in the DB
        }


and for the database interaction code you can refer this:

A Beginner's Tutorial for Understanding ADO.NET[^]
 
Share this answer
 
when you saving data if your page is not postback on dropdownlist selection than check that if in textbox data exist than save textbox data or not than save dropdownlist selected value data.
 
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