如何分割以逗号分隔的字符串插入到ASP.NET C#中的Sql数据库中 [英] how to split string seperated by commas & insert into Sql Database in asp.net c#
本文介绍了如何分割以逗号分隔的字符串插入到ASP.NET C#中的Sql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何分割用逗号分隔的字符串并插入asp.net中的Sql数据库中c#
how to split string seperated by commas & insert into Sql Database in asp.net c#
推荐答案
尝试以下示例
Try this example
static void Main()
{
string s = "there,is,a,cat";
//
// Split string on comma.
// ... This will separate all the words.
//
string[] words = s.Split(',');
foreach (string word in words)
{
//Insert each wrd into database
//insert(word);
}
}
检查此
Hi ,
Check this
string RValue = "1233,frrrr,rrrryy";
string[] VExist = RValue.Split(',');
foreach (string item in VExist)
{
using (
SqlConnection con =
new SqlConnection(""))
{
using (SqlCommand cmd = new SqlCommand("usp_test", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@tst", VExist[0]);
cmd.Parameters.AddWithValue("@tst2", VExist[1]);
cmd.Parameters.AddWithValue("@tst2", VExist[2]);
cmd.ExecuteNonQuery();
}
}
}
最好的问候
米特瓦里(M.Mitwalli)
Best Regards
M.Mitwalli
这篇关于如何分割以逗号分隔的字符串插入到ASP.NET C#中的Sql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文