保存代码/ ID但查看名称 [英] Save the code/id but view the name

查看:93
本文介绍了保存代码/ ID但查看名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表格第一个包含所有颜色及其对应的颜色代码,第二个是我要保存所有油漆销售记录的地方。防爆。我想在第二张表(Boysen,1500,3,蓝色)中插入品牌,成本,数量和颜色,并从第一张颜色表中显示:



颜色代码|颜色名称

0001 |蓝色

0002 |红色

0003 |栗色

....



我想要的是当文本框的值等于颜色时保存颜色代码名称。当我要使用数据网格视图回到文本框查看它时,颜色名称应该不是颜色代码....现在有意义吗?对不起太多的困惑....



我尝试了什么:



con.Open();

DataTable dt = new DataTable();

adapt = new SqlDataAdapter(SELECT colorname,colorcode FROM tblcolor,con);

adapt.Fill(dt);

Form1 f = new Form1();

f.dataGridView1.DataSource = dt;



textboxcolor.AutoCompleteMode = AutoCompleteMode.Suggest;

foreach(dt.Rows中的DataRow行)



textboxcolor.AutoCompleteCustomSource.Add(row [colorname] as string);

con.Close();









所以我遇到的麻烦是我可以通过autosuggest选择颜色名称,但我需要的是保存颜色代码不是colorname,当我查看它时,我应该看到colorname。

I have 2 tables 1st contains all the colors and its corresponding color code, 2nd is where i want to save all the record of sales of paint. Ex. I want to insert the brand, cost, qty and what color of paint to the 2nd table (Boysen,1500,3,Blue) and from the 1st table of colors shows:

color code | color name
0001 | Blue
0002 | Red
0003 | Maroon
....

What I want is to save the color code when the value of the text box is equal to the color name. and when I am going to view it using data grid view back to text box the color name should appear not the color code.... Make sense now? sorry for too much confusion....

What I have tried:

con.Open();
DataTable dt=new DataTable();
adapt=new SqlDataAdapter("SELECT colorname,colorcode FROM tblcolor", con);
adapt.Fill(dt);
Form1 f=new Form1();
f.dataGridView1.DataSource=dt;

textboxcolor.AutoCompleteMode=AutoCompleteMode.Suggest;
foreach(DataRow row in dt.Rows)

textboxcolor.AutoCompleteCustomSource.Add(row["colorname"] as string);
con.Close();




So what I'm having trouble is I am able to select the colorname through autosuggest but what I need is to save the colorcode not the colorname and when I view it I should see the colorname.

推荐答案

使用JOIN:

Use a JOIN:
SELECT a.Brand, a.Cost, a.Qty, c.[Color Name] FROM MyTable a
JOIN Colors c ON c.[Color Code] = a.[Color Code]


这篇关于保存代码/ ID但查看名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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