内容不会在句子中分割,也不会存储在表格中 [英] Contents are not splits up in sentence and its not store in table
问题描述
我的代码行有内容,我必须使用gridview中的按钮将其拆分为句子并存储到表中,所以我写了这段代码。但它不工作
x.aspx:
i code to row has content and i have to split it into sentence using button in gridview and store into table so i have written this code.but its not working
x.aspx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="219px" OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand1">
<Columns>
<asp:BoundField DataField="ContentText" HeaderText="ContentText" SortExpression="ContentText" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btn1" Text="Split into Sentences" runat="server" CommandName="click" CommandArgument="<%# Container.DisplayIndex %>"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Jobe101ConnectionString %>" SelectCommand="SELECT [ContentText] FROM [Contents]"></asp:SqlDataSource>
x.aspx。 cs
protected void GridView1_RowCommand1(object sender,GridViewCommandEventArgs e)
{
if(e.CommandName ==click)
{
int index = Convert.ToInt32(e.CommandArgument.ToString ());
GridViewRow row = GridView1.Rows [index];
var text = GridView1.Rows [index] .Cells [0] .Text;
String [] sentences = Regex.Split(text,@(?< = [。!?])\ s +(?= \p {Lt})); < br $>
System.Data.DataTable dt1 = new System.Data.DataTable();
dt1.Columns .Add(SentenceText);
foreach(句子中的字符串值)
{
dt1。 Rows.Add(value);
}
string sql =;
string apply =;
for(int i = 0;我< dt1.Rows.Count; i ++)
{
sql = sql +insert into Sentences(SentenceText)select'+ dt1.Rows [i] [SentenceText]。ToString()+ '哪里不存在(从Sentences中选择SentenceText ='+ dt1.Rows [i] [SentenceText]。ToString()+');
apply = apply +insert进入ContentSentences(ContentID)从内容中选择ContentID;
}
}
什么是问题??? /
x.aspx.cs
protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e )
{
if (e.CommandName == "click")
{
int index = Convert.ToInt32(e.CommandArgument.ToString());
GridViewRow row = GridView1.Rows[index];
var text = GridView1.Rows[index].Cells[0].Text;
String[] sentences = Regex.Split(text, @"(?<=[.!?])\s+(?=\p{Lt})");
System.Data.DataTable dt1 = new System.Data.DataTable();
dt1.Columns.Add("SentenceText");
foreach (string value in sentences)
{
dt1.Rows.Add(value);
}
string sql = "";
string apply = "";
for (int i = 0; i < dt1.Rows.Count; i++)
{
sql = sql + "insert into Sentences(SentenceText) select '" + dt1.Rows[i]["SentenceText"].ToString() + "' where not exists(select SentenceText from Sentences where='" + dt1.Rows[i]["SentenceText"].ToString() + "')";
apply = apply + "insert into ContentSentences(ContentID)select ContentID from Contents";
}
}
what is problem???/
推荐答案
ConnectionStrings:Jobe101ConnectionString %> SelectCommand = SELECT [ContentText] FROM [Contents] > < / asp:SqlDataSource >
ConnectionStrings:Jobe101ConnectionString %>" SelectCommand="SELECT [ContentText] FROM [Contents]"></asp:SqlDataSource>
x.aspx.cs
protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName ==click)
{
int index = Convert.ToInt32(e.CommandArgument.ToString());
GridViewRow row = GridView1.Rows [index];
var text = GridView1.Rows [index] .Cells [0] .Text;
String [] sentence = Regex.Split(text,@(?< = [。!?])\ s +(?= \p {Lt}));
System.Data.DataTable dt1 = new System.Data.DataTable();
dt1.Columns.Add(SentenceText);
foreach(句子中的字符串值)
{
dt1.Rows.Add(value);
}
string sql =;
string apply =;
for(int i = 0;我< dt1.Rows.Count; i ++)
{
sql = sql +insert into Sentences(SentenceText)select'+ dt1.Rows [i] [SentenceText]。ToString()+ '哪里不存在(从Sentences中选择SentenceText ='+ dt1.Rows [i] [SentenceText]。ToString()+');
apply = apply +insert进入ContentSentences(ContentID)从内容中选择ContentID;
}
}
什么是问题??? /
x.aspx.cs
protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e )
{
if (e.CommandName == "click")
{
int index = Convert.ToInt32(e.CommandArgument.ToString());
GridViewRow row = GridView1.Rows[index];
var text = GridView1.Rows[index].Cells[0].Text;
String[] sentences = Regex.Split(text, @"(?<=[.!?])\s+(?=\p{Lt})");
System.Data.DataTable dt1 = new System.Data.DataTable();
dt1.Columns.Add("SentenceText");
foreach (string value in sentences)
{
dt1.Rows.Add(value);
}
string sql = "";
string apply = "";
for (int i = 0; i < dt1.Rows.Count; i++)
{
sql = sql + "insert into Sentences(SentenceText) select '" + dt1.Rows[i]["SentenceText"].ToString() + "' where not exists(select SentenceText from Sentences where='" + dt1.Rows[i]["SentenceText"].ToString() + "')";
apply = apply + "insert into ContentSentences(ContentID)select ContentID from Contents";
}
}
what is problem???/
你必须管理RowIndex
的情况网格是-1。在你的情况下,你应该在访问行单元格之前添加下一个代码。
You have to manage also the case whenRowIndex
of the grid is -1. In you case you should add the next code before to access the row cell.
if(index <0)
{
return;
}
//
GridViewRow row = GridView1.Rows[index];
//...
这篇关于内容不会在句子中分割,也不会存储在表格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!