如何在保存按钮单击时将下拉列表中的选定数据保存到数据库中 [英] how to save the selected data in dropdownlist into the database on save button click

查看:111
本文介绍了如何在保存按钮单击时将下拉列表中的选定数据保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请尽快给我一些解决方案...

pls give me some solution asap...

推荐答案

首先你必须考虑如何获得选定价值



如果您需要获取所选文本并希望保存



ex。

First you have to consider that how to get selected value

If you need to get selected text and want save

ex.
string departmentName=ddlDepartment.SelectedItem.Text;
int id= Convert.ToInt32(ddlDepartment.SelectedValue);



然后进行查询以保存表格中的数据



看我要去保存所选值的id


Then make a query to save the data in your table

see I am going to save id which is selected value

string query="insert into table(UserName,DepartmentID)values('"+txtUserName.text+"',"+id+")";
SqlCommand cmd=new SqlCommand(query,connection);

cmd.ExecuteNonQuery();






试试这个



Hi ,

Try this

try
{
myconnection.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into EmployeesDetails (EmpName,EmpQualification) values (@EmpName,@EmpQualification)";
cmd.Parameters.AddWithValue("@EmpName", txtEmpName.Text);
cmd.Parameters.AddWithValue("@EmpQualification", drpQualification.SelectedValue);
cmd.Connection = myconnection;
cmd.ExecuteNonQuery();
}





好​​运



Good Luck


这篇关于如何在保存按钮单击时将下拉列表中的选定数据保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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