Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys!
i have two problems
first:
i concatenate two column through select query
this is the query
"select concat (Vehicle.Vehicle_Name, '-' , Vehicle.Vehicle_Model) as [Vehicle Name] from Vehicle"
and assign to a text-box1
now i want to access the id of the textbox1.text

Second:
is there any built-in library in c# to validate our winform
thanks

What I have tried:

i tried a lot but didn't find something beautiful
Posted
Updated 29-Dec-18 1:55am

1 solution

1) What ID? Text strings do not have an ID: they are just that: strings. And when you concatenate two strings, you "break the association" with any particular row in the DB. It may be that you can "reunite" the string with the row by undoing the concatenation and SELECTing back from the DB, but it's not guaranteed to work in all cases. In this, it might, but - it's a poor idea.

A better idea is to create a class which contains the row ID, and the two strings - then override ToString to concatenate them. Fill that from your DB, and use a ComboBox instead of a text box to let the user pick the make and model. That way, you can use the selected item to get back the class instance and you have your rowID available.

2) No. Think about it: do you have any idea what validation I might want to do on my forms? So why would the system (or anyone else) have any more idea what validation you want?
 
Share this answer
 
Comments
Member 13985914 29-Dec-18 8:24am    
validation like e.g i have a textbox which will only accept int data type not string

this can be done by if else condition but i want a library or class to validate my form object
OriginalGriff 29-Dec-18 8:35am    
Have you considered int.TryParse?
Member 13985914 29-Dec-18 8:38am    
i can do this by int.tryparse etc but i don't want coz i want a library that do my validation
OriginalGriff 29-Dec-18 8:45am    
And how do you expect a "library" to know you want an integer?

Think about it ... you are going to spend a lot longer trying to get the work done for you than you would writing a quick method yourself ...
And you will end up writing it yourself anyway! :laugh:

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