用逗号分割字符串并保存在我尝试的数据库中,但它无法正常工作 [英] split the string with comma and save in the database i tried but it is not working

查看:71
本文介绍了用逗号分割字符串并保存在我尝试的数据库中,但它无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for (int i = 0; i < datagridView.RowCount; i++)
     {
       for (int j = 2; j < datagridView.ColumnCount; j++)
       {
         if (datagridView[j, i].Value.ToString().Contains(","))
         {           
           string strvalue = datagridView[j, i].Value.ToString() + ", " + cb_Course.Text;
           string[] strarray = strvalue.Split('/');
           foreach(object obj in strarray)
           {
           //in that my insert query         
           }
         }
       }
     }





当我运行上面的代码并保存在数据库。



记录不保存我的上述代码有什么问题





我的插入查询如下;





when i run the above code and save in the database.

record not saving what is the problem in my above code


My insert query as follows;

sql = "insert into Tb_SCh_TIme_Table([Sch_Date], [Session], [Course],[Faculty_Code])" + " values ('" + Convert.ToDateTime(datagridView.Rows[i].Cells[0].Value.ToString()) + "', " + int.Parse(datagridView.Rows[i].Cells[1].Value.ToString()) + ", '" + datagridView[j, i].Value.ToString() + "','" + datagridView.Columns[j].HeaderText.ToString() + "')";







当我在datagridview中运行时,我的代码有什么问题值在单元格中如下



REO,MFA



i想分割并保存在数据库。




what is the problem in my code , when i run in the datagridview two values are there in a cell as follows

REO,MFA

i want to split and save in the database.

推荐答案

你必须使用Split('','')而不是Split(''/'')
you have to use Split('','') instead of Split(''/'')


这篇关于用逗号分割字符串并保存在我尝试的数据库中,但它无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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