Click here to Skip to main content
15,885,182 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi

I want to select the "company name" from the dropdown but...... "company code" should be saved in the database as i click on the submit button....


please provide the code in C# (for web application) using SqlDataAdaptor class


thanks.
Posted
Updated 20-Feb-12 19:47pm
v2
Comments
AmitGajjar 21-Feb-12 1:44am    
Don't take it personally, just a suggestion. this is very basic dear. please go through the Data Access through ADO.NET and use of other controls. posting for particular problem would not be permanent solution. if you would like to be a programmer, read MSDN as much as possible.

thanks
-Amit
Rajesh Anuhya 21-Feb-12 1:47am    
Edited.
--RA

try this
  strsql = "select companyname,companycode from company"

           
'execute query and save it in datatable
              dt = objdb.getTable(strsql)
          

            combo1.DataSource = dt ;
            combo1.DataValueField = tblfunction.Columns(1).Caption;
            combo1.DataTextField = tblfunction.Columns(0).Caption;
            combo1.DataBind();
            combo1.Text = "select";



it ll display company name in drop down and value as company code
for eg
combo1.text=company name
combo1.SelectedValue = company code
 
Share this answer
 
On page load use this
C#
dropdown.DataSource = GetData(); can be DataTable
dropdown.DataTextField = Name Column;
dropdown.DataValueField = Code Column;
dropdown.DataBind();

when you want to use
C#
string company = dropdown.SelectedValue;
 
Share this answer
 
C#
public void SaveDetails()
   {

       string str = "insert into temp (emp_code,emp_name,paswrd,domain_name,dpt_code,dpt_name,email,role,CompCode) values (@emp_code,@emp_name,@paswrd,@domain_name,@dpt_code,@dpt_name,@email,@role,@CompCode)";

           cmd = new SqlCommand(str, cn);

           cmd.Parameters.Add("@emp_code", SqlDbType.Int).Value = Convert.ToInt32(txtEmpCode.Text);
          // cmd.Parameters.Add("@emp_id", SqlDbType.Int).Value = 1;
           cmd.Parameters.Add("@emp_name", SqlDbType.VarChar).Value = txtEmpName.Text;
           cmd.Parameters.Add("@paswrd", SqlDbType.VarChar).Value = txtPwd.Text;
           cmd.Parameters.Add("@domain_name", SqlDbType.VarChar).Value = txtDomainName.Text;
           cmd.Parameters.Add("@dpt_code", SqlDbType.VarChar).Value = DDLDeptName.SelectedValue;
           cmd.Parameters.Add("@dpt_name", SqlDbType.VarChar).Value = DDLDeptName.Text;
           cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = txtEmail.Text;
           cmd.Parameters.Add("@role", SqlDbType.Int).Value = Convert.ToInt32(DDLRole.SelectedIndex);
           cmd.Parameters.Add("@CompCode", SqlDbType.Int).Value = Convert.ToInt32(DDL_CompName.DataValueField="comp_code");    // this is the line where i m faceing the problem.... please tell me what to do here

it is givin the error as "Input string was not in a correct format."

       cmd.ExecuteNonQuery();

           LBLSuccessfullySaved.Text = "Data Saved Successfully";

           // calling the "blankall" method to remove all the entrys
           blankall();


   }
 
Share this answer
 
Comments
Praveen2886 21-Feb-12 2:23am    
change the line like this
cmd.Parameters.Add("@CompCode", SqlDbType.Int).Value = Convert.ToInt32(DDL_CompName.DataValueField);
try this

cmd.Parameters.Add("@CompCode", SqlDbType.Int32).Value = Convert.ToInt32(DDL_CompName.DataValueField);
 
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