Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello
i have three string variable cb1ID,cb2ID ,cb3ID in my programe and that three content three different value i want parameter string that can insert three string in same colomn.

What I have tried:

i have try this but this is not usefull for me it is doing adition
cmd.Parameters.Add(new SqlParameter("@ID", cb1ID+cb2ID+cb3ID));
Posted
Updated 5-Oct-16 4:23am
v2
Comments
[no name] 5-Oct-16 9:15am    
"i have try this but this is not usefull for me it is doing adition", yes and what else did you expect it to do? That is exactly what you said you wanted to do and that is what your code is doing. So what is the problem?
AZHAR SAYYAD 5-Oct-16 9:27am    
actually there is 3 different variable and i want to store this three variable one by one in database i dont want to addition i want insert into this three variable in database
[no name] 5-Oct-16 9:35am    
Okay... so write some code to do that then. How you would expect that to happen with what you wrote is a mystery to me.
Karthik_Mahalingam 5-Oct-16 10:31am    
how do you want to store in db table?
as one item or 3 items combined as 'a,b,c' ??

If those IDs are numbers, of course they will add up using + operator. If you want string, then use the appropriate Convert.ToString Method (System)[^].
BTW, why do you want to concatenate IDs? How are you going to differentiate them subsequently? Rightfully, you should store them separately. Learn more 1NF, 2NF, 3NF and BCNF in Database Normalization[^]
 
Share this answer
 
v3
Assuming you want commas between them:
C#
cmd.Parameters.Add(new SqlParameter("@ID", string.Format("{0},{1},{2}",cb1ID,cb2ID,cb3ID));
 
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