Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 22-Aug-17 3:28am
v2

1 solution

Use a JOIN:
C#
SELECT a.Brand, a.Cost, a.Qty, c.[Color Name] FROM MyTable a
JOIN Colors c ON c.[Color Code] = a.[Color Code]
 
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