简体   繁体   English

在SQL Server 2008表中存储GridView数据时出现尾随空间问题

[英]Having trailing space issue while storing GridView data in SQL Server 2008 table

As per my requirement there is need of Uploding Excel data in SQL Server 2008 根据我的要求,需要在SQL Server 2008中上载Excel数据

But there is one issue..... 但是有一个问题.....

WHEN I am uploading an Excel sheet and showing it's content in Gridview and then I am storing it in SQL Server 2008 database; 当我上载Excel工作表并在Gridview中显示其内容,然后将其存储在SQL Server 2008数据库中时;

In the GridView, Excel data is showing perfectly, but when I am storing it into the database, then at the end of string   在GridView中,Excel数据可以完美显示,但是当我将其存储到数据库中时,则在字符串 的末尾  is inserted... 已插入...

Stored data in table is PETER  表中存储的数据为PETER  while it should be PETER 虽然应该是PETER

I have tried using the .Trim() method also but nothing is worked 我也尝试过使用.Trim()方法,但是没有任何效果

foreach (GridViewRow g1 in grvExcelData.Rows)
{
   try
   {
       name = grvExcelData.Rows[g1.RowIndex].Cells[2].Text.Trim();

Here's a sample of my data: 这是我的数据示例:

  96086 IT085   PATEL RUCHIKKUMAR MAHENDRABHAI     IT  6   2009-13

  or     is the html code for non breaking space . 不间断空格的html代码。

Use this to get rid of it. 用它摆脱它。

name = grvExcelData.Rows[g1.RowIndex].Cells[2].Text.Replace(@" ", "");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM