通过C#中的插入查询在数据库中插入逗号(,) [英] Insert comma(,) in database through insert query in C#

查看:60
本文介绍了通过C#中的插入查询在数据库中插入逗号(,)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我必须通过C#代码插入(,)在sqlserver中的表中的字段,

怎么能我这样做了吗?





请帮忙。



提前致谢,

Supriya

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

推荐答案

你遇到的问题是什么,你可以像这样使用。



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

insert into mytable values('011,874000,275581',1)


亲爱的Supriya,



此链接可能会帮助您解决问题并将逗号值视为字符串,以便将其插入SQL数据字段。



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



我希望这能帮到你。



谢谢
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


试试这个



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();
            
        }
    }
}


这篇关于通过C#中的插入查询在数据库中插入逗号(,)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆