请帮助...我想选择“公司名称" ... [英] pls help...... i want to select the "company name" ...

查看:68
本文介绍了请帮助...我想选择“公司名称" ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

...

我有一个下拉列表,其中有我所有的公司名称" ....但是在插入记录时,只有公司代码"必须保存在数据库中.名字...

以下是我用来保存详细信息的方法...
谢谢


...

i have a dropdownlist in which i have all the "company names"........ but at the time of insertion of the record only the "company code" must be saved in the database.... not the selected name......

the following isthe method i m using to save the deatils......
thanks


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();


   }

推荐答案

cmd.Parameters.Add("@CompCode", SqlDbType.Int).Value = Convert.ToInt32(DDL_CompName.DataValueField="comp_code");


看看你在做什么:


Look at what you are doing:

DDL_CompName.DataValueField="comp_code"

将返回一个布尔值:对或错.您只需要检索字段并进行转换即可:

will return a bool: true or false. You need to just retrieve the field, and convert that:

cmd.Parameters.Add("@CompCode", SqlDbType.Int).Value = Convert.ToInt32(DDL_CompName.DataValueField);

(这假设您首先设置了DataValue字段!)

(This assumes that you have set the DataValue field in the first place!)


这篇关于请帮助...我想选择“公司名称" ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆