Click here to Skip to main content
14,426,633 members
Rate this:
Please Sign up or sign in to vote.
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 2: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.
Rate this:
Please Sign up or sign in to vote.

Solution 1

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

insert into mytable values('011,874000,275581',1)
   
Comments
Supriya Srivastav 6-Jan-12 6:18am
   
Thnx,I don't know where I was wrong,but finally got out of it.
Rate this:
Please Sign up or sign in to vote.

Solution 2

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
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 3

Try this

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();
            
        }
    }
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

in windows character map
font Consolas
use char U+201A and its look like comma . and inserted in sql database by query
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100