Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more: , +
Dear All,

I have to insert (,) in a field in table in sqlserver through C# code,
how can I do so?


Please help.

Thanks in advance,
Supriya
Posted
Updated 5-May-19 1:27am
Comments
Prasad_Kulkarni 6-Jan-12 6:13am    
can u post your code?
get some help from this query..
INSERT INTO M_OutwardNumber([OutwardNumber], [OutwardDate])
VALUES ('1,','2011-01-01')
AmitGajjar 6-Jan-12 7:35am    
but the best way to do it through StoredProcedure.

What is the Problem you are getting , you can use like this.

insert into mytable values('011,874000,275581',1)
 
Share this answer
 
Comments
Supriya Srivastav 6-Jan-12 6:18am    
Thnx,I don't know where I was wrong,but finally got out of it.
Dear Supriya,

This link might help you out with your confusion and treat the comma value as string in order to insert it into the SQL Data field.

http://forums.asp.net/t/960972.aspx/1[^]

I hope this will help you out.

Thanks
 
Share this answer
 
v2
Try this

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data.Sql;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            SqlConnection con = new SqlConnection("user id=sa;" +
                                       "password=sa@123;server=10.2.30.20;" +
                                       "Trusted_Connection=yes;" +
                                       "database=DBName; " +
                                       "connection timeout=30");

            string CSVString = "English,Marathi,Hindi";

            string query = "INSERT INTO LangKnown SELECT 1 ,'" + CSVString + "'";
            SqlCommand cmd = new SqlCommand(query, con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            
        }
    }
}
 
Share this answer
 
in windows character map
font Consolas
use char U+201A and its look like comma . and inserted in sql database by query
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 5-May-19 9:09am    
It is not considered good behavior to answer 7 years old questions... Especially with an answer already accepted...
Do not turn it into a common one...

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