关于从两列到单个下拉列表的数据的问题 [英] Question about data taken from two columns to a single dropdown list
问题描述
先生,
我有从数据库中的两列数据到单个下拉列表的代码。我的代码是:
Sir,
I have the code for taking data from two columns from the database to a single dropdown list.My code is :
drpMaterialName.DataSource = ClassLibrary1.mainclass.dset("Purchase_Material_Name", "");
drpMaterialName.DataValueField = "fullname";
drpMaterialName.DataTextField = "fullname";
DataBind();
sql代码:
sql code:
ALTER PROCEDURE Purchase_Material_Name
AS
select Material_name+''+Size as fullname from Materials
RETURN
我从两列到下拉列表中获得了值。但问题是我需要你的帮助将这些选定的数据保存到两列
I got vales from two columns to the dropdown. But the thing is i need your help to save these selected data into two columns
推荐答案
我建议你在两列之间使用某种分隔符
例如更改您查询以下
选择Material_name +'!'+尺寸作为材料的全名
唯一需要注意的是分隔符在任何列中都不存在。由于我不知道你的数据,我提供了一个!作为分隔符。
您将更好地判断分隔符。
当您从下拉控件中收到值时,您可能会分裂分隔符处的数据值,并在insert语句中使用这些分隔值,并将其插入两个不同的列。
I would suggest that you use some kind of a separator between the two columns
for example change you query to the following
select Material_name+'!'+Size as fullname from Materials
The only thing you need to be careful about is that the separator does not exists in any of the columns. As I don't know your data I have provided a "!" as the separator.
You will be the better judge of the separator.
When you receive the value from the dropdown control you may split the data value at the separator and use these separated values in your insert statement and insert it in the two different columns.
试试这个
在你的查询中应该是两个列名之间的一个空格
选择Material_name +''+尺寸作为材料的全名
try this
in your query should be one space between two column name
select Material_name+' '+Size as fullname from Materials
String [] str=drpdownList.SelectedItem.ToString().Split('-');
String str1=str[0].Trim();
String str2=str[1].Trim();
str1获取第一列数据和str2获取第二列数据
了解更多关于拆分功能的信息
http://www.webblogsforyou .com / how-to-split-string-date-into-day-month-year / [ ^ ]
嗨Dude,
改变这样的代码
1)存储过程:
Hi Dude,
Alter your code like this
1)Stored Procedure :
SELECT
(ISNULL(Material_name,'')+''+ISNULL(Size,'')) [MaterialNameText],
(ISNULL(Material_name,'')+'#separator#'+ISNULL(Size,'')) [MaterialNameValue]
FROM Materials
注意:在SQL concordinate中尝试使用isnull
2)在C#中代码
NOTE: In SQL concordinate try to use isnull
2)In C# Code
drpMaterialName.DataSource = ClassLibrary1.mainclass.dset("Purchase_Material_Name", "");
drpMaterialName.DataValueField = "MaterialNameValue";
drpMaterialName.DataTextField = "MaterialNameText";
DataBind()
在数据值字段中绑定MaterialNameValue(它包含分隔符)
绑定文本字段中的MaterialNameText
Bind MaterialNameValue in Data value Field (it contain separator)
Bind MaterialNameText in Text Field
String [] strValue=Convert.ToString(drpdownList.SelectedValue).Split('#separator#');
String Material_name=strValue[0].Trim();
String Size=strValue[1].Trim();
现在你可以很容易地将值存入db
注意:尝试使用Convert.ToString( )放入TOString()
Now you can easily store value into db
Note:Try to use Convert.ToString() insted of TOString()
这篇关于关于从两列到单个下拉列表的数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!